diff --git a/.changeset/config.json b/.changeset/config.json
index 64bfe8e522..5e8716336b 100644
--- a/.changeset/config.json
+++ b/.changeset/config.json
@@ -1,11 +1,6 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json",
- "changelog": [
- "@remix-run/changelog-github",
- {
- "repo": "triggerdotdev/trigger.dev"
- }
- ],
+ "changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [
[
diff --git a/.changeset/kind-penguins-try.md b/.changeset/kind-penguins-try.md
new file mode 100644
index 0000000000..763013956e
--- /dev/null
+++ b/.changeset/kind-penguins-try.md
@@ -0,0 +1,7 @@
+---
+"@trigger.dev/sdk": patch
+"@trigger.dev/react": patch
+"@trigger.dev/core": patch
+---
+
+You can create statuses in your Jobs that can then be read using React hooks
diff --git a/apps/webapp/app/routes/api.v1.runs.$runId.statuses.$id.ts b/apps/webapp/app/routes/api.v1.runs.$runId.statuses.$id.ts
new file mode 100644
index 0000000000..e547534231
--- /dev/null
+++ b/apps/webapp/app/routes/api.v1.runs.$runId.statuses.$id.ts
@@ -0,0 +1,151 @@
+import type { ActionArgs } from "@remix-run/server-runtime";
+import { json } from "@remix-run/server-runtime";
+import { TaskStatus } from "@trigger.dev/database";
+import {
+ RunTaskBodyOutput,
+ RunTaskBodyOutputSchema,
+ ServerTask,
+ StatusHistory,
+ StatusHistorySchema,
+ StatusUpdate,
+ StatusUpdateData,
+ StatusUpdateSchema,
+ StatusUpdateState,
+} from "@trigger.dev/core";
+import { z } from "zod";
+import { $transaction, PrismaClient, prisma } from "~/db.server";
+import { taskWithAttemptsToServerTask } from "~/models/task.server";
+import { authenticateApiRequest } from "~/services/apiAuth.server";
+import { logger } from "~/services/logger.server";
+import { ulid } from "~/services/ulid.server";
+import { workerQueue } from "~/services/worker.server";
+import { JobRunStatusRecordSchema } from "@trigger.dev/core";
+
+const ParamsSchema = z.object({
+ runId: z.string(),
+ id: z.string(),
+});
+
+export async function action({ request, params }: ActionArgs) {
+ // Ensure this is a POST request
+ if (request.method.toUpperCase() !== "PUT") {
+ return { status: 405, body: "Method Not Allowed" };
+ }
+
+ // Next authenticate the request
+ const authenticationResult = await authenticateApiRequest(request);
+
+ if (!authenticationResult) {
+ return json({ error: "Invalid or Missing API key" }, { status: 401 });
+ }
+
+ const { runId, id } = ParamsSchema.parse(params);
+
+ // Now parse the request body
+ const anyBody = await request.json();
+
+ logger.debug("SetStatusService.call() request body", {
+ body: anyBody,
+ runId,
+ id,
+ });
+
+ const body = StatusUpdateSchema.safeParse(anyBody);
+
+ if (!body.success) {
+ return json({ error: "Invalid request body" }, { status: 400 });
+ }
+
+ const service = new SetStatusService();
+
+ try {
+ const statusRecord = await service.call(runId, id, body.data);
+
+ logger.debug("SetStatusService.call() response body", {
+ runId,
+ id,
+ statusRecord,
+ });
+
+ if (!statusRecord) {
+ return json({ error: "Something went wrong" }, { status: 500 });
+ }
+
+ const status = JobRunStatusRecordSchema.parse({
+ ...statusRecord,
+ state: statusRecord.state ?? undefined,
+ history: statusRecord.history ?? undefined,
+ data: statusRecord.data ?? undefined,
+ });
+
+ return json(status);
+ } catch (error) {
+ if (error instanceof Error) {
+ return json({ error: error.message }, { status: 400 });
+ }
+
+ return json({ error: "Something went wrong" }, { status: 500 });
+ }
+}
+
+export class SetStatusService {
+ #prismaClient: PrismaClient;
+
+ constructor(prismaClient: PrismaClient = prisma) {
+ this.#prismaClient = prismaClient;
+ }
+
+ public async call(runId: string, id: string, status: StatusUpdate) {
+ const statusRecord = await $transaction(this.#prismaClient, async (tx) => {
+ const existingStatus = await tx.jobRunStatusRecord.findUnique({
+ where: {
+ runId_key: {
+ runId,
+ key: id,
+ },
+ },
+ });
+
+ const history: StatusHistory = [];
+ const historyResult = StatusHistorySchema.safeParse(existingStatus?.history);
+ if (historyResult.success) {
+ history.push(...historyResult.data);
+ }
+ if (existingStatus) {
+ history.push({
+ label: existingStatus.label,
+ state: (existingStatus.state ?? undefined) as StatusUpdateState,
+ data: (existingStatus.data ?? undefined) as StatusUpdateData,
+ });
+ }
+
+ const updatedStatus = await tx.jobRunStatusRecord.upsert({
+ where: {
+ runId_key: {
+ runId,
+ key: id,
+ },
+ },
+ create: {
+ key: id,
+ runId,
+ //this shouldn't ever use the id in reality, as the SDK makess it compulsory on the first call
+ label: status.label ?? id,
+ state: status.state,
+ data: status.data as any,
+ history: [],
+ },
+ update: {
+ label: status.label,
+ state: status.state,
+ data: status.data as any,
+ history: history as any[],
+ },
+ });
+
+ return updatedStatus;
+ });
+
+ return statusRecord;
+ }
+}
diff --git a/apps/webapp/app/routes/api.v1.runs.$runId.statuses.ts b/apps/webapp/app/routes/api.v1.runs.$runId.statuses.ts
new file mode 100644
index 0000000000..f7e6351de2
--- /dev/null
+++ b/apps/webapp/app/routes/api.v1.runs.$runId.statuses.ts
@@ -0,0 +1,82 @@
+import type { LoaderArgs } from "@remix-run/server-runtime";
+import { json } from "@remix-run/server-runtime";
+import { JobRunStatusRecordSchema } from "@trigger.dev/core";
+import { z } from "zod";
+import { prisma } from "~/db.server";
+import { authenticateApiRequest } from "~/services/apiAuth.server";
+import { logger } from "~/services/logger.server";
+import { apiCors } from "~/utils/apiCors";
+
+const ParamsSchema = z.object({
+ runId: z.string(),
+});
+
+const RecordsSchema = z.array(JobRunStatusRecordSchema);
+
+export async function loader({ request, params }: LoaderArgs) {
+ if (request.method.toUpperCase() === "OPTIONS") {
+ return apiCors(request, json({}));
+ }
+
+ // Next authenticate the request
+ const authenticationResult = await authenticateApiRequest(request, { allowPublicKey: true });
+
+ if (!authenticationResult) {
+ return apiCors(request, json({ error: "Invalid or Missing API key" }, { status: 401 }));
+ }
+
+ const { runId } = ParamsSchema.parse(params);
+
+ logger.debug("Get run statuses", {
+ runId,
+ });
+
+ try {
+ const run = await prisma.jobRun.findUnique({
+ where: {
+ id: runId,
+ },
+ select: {
+ id: true,
+ status: true,
+ output: true,
+ statuses: {
+ orderBy: {
+ createdAt: "asc",
+ },
+ },
+ },
+ });
+
+ if (!run) {
+ return apiCors(request, json({ error: `No run found for id ${runId}` }, { status: 404 }));
+ }
+
+ const parsedStatuses = RecordsSchema.parse(
+ run.statuses.map((s) => ({
+ ...s,
+ state: s.state ?? undefined,
+ data: s.data ?? undefined,
+ history: s.history ?? undefined,
+ }))
+ );
+
+ return apiCors(
+ request,
+ json({
+ run: {
+ id: run.id,
+ status: run.status,
+ output: run.output,
+ },
+ statuses: parsedStatuses,
+ })
+ );
+ } catch (error) {
+ if (error instanceof Error) {
+ return apiCors(request, json({ error: error.message }, { status: 400 }));
+ }
+
+ return apiCors(request, json({ error: "Something went wrong" }, { status: 500 }));
+ }
+}
diff --git a/apps/webapp/app/routes/api.v1.runs.$runId.ts b/apps/webapp/app/routes/api.v1.runs.$runId.ts
index 973d71f787..e1273654f8 100644
--- a/apps/webapp/app/routes/api.v1.runs.$runId.ts
+++ b/apps/webapp/app/routes/api.v1.runs.$runId.ts
@@ -1,9 +1,8 @@
import type { LoaderArgs } from "@remix-run/server-runtime";
import { json } from "@remix-run/server-runtime";
-import { cors } from "remix-utils";
import { z } from "zod";
import { prisma } from "~/db.server";
-import { authenticateApiRequest, getApiKeyFromRequest } from "~/services/apiAuth.server";
+import { authenticateApiRequest } from "~/services/apiAuth.server";
import { apiCors } from "~/utils/apiCors";
import { taskListToTree } from "~/utils/taskListToTree";
@@ -93,6 +92,9 @@ export async function loader({ request, params }: LoaderArgs) {
}
: undefined,
},
+ statuses: {
+ select: { key: true, label: true, state: true, data: true, history: true },
+ },
},
});
@@ -122,6 +124,12 @@ export async function loader({ request, params }: LoaderArgs) {
const { parentId, ...rest } = task;
return { ...rest };
}),
+ statuses: jobRun.statuses.map((s) => ({
+ ...s,
+ state: s.state ?? undefined,
+ data: s.data ?? undefined,
+ history: s.history ?? undefined,
+ })),
nextCursor: nextTask ? nextTask.id : undefined,
})
);
diff --git a/docs/_snippets/how-to-get-run-id.mdx b/docs/_snippets/how-to-get-run-id.mdx
new file mode 100644
index 0000000000..8d5d372431
--- /dev/null
+++ b/docs/_snippets/how-to-get-run-id.mdx
@@ -0,0 +1,5 @@
+
Runs: {data.runs?.length}
++ Run {run.id}: {run.status} +
+Status: {data.status}
++ Task {task.id}: {task.status} +
+Status: {data.status}
++ Task {task.id}: {task.status} +
+Loading...
; + } + + if (fetchStatus === "error") { + return ( +{error.name}
+{error.message}
++ {status.label}: {status.state} +
+ //will render the memes as images + {urls?.map((url) =>
+ {JSON.stringify(run.output, null, 2)}
+
+ )}
+ >
+ );
+}
+```
+
+## useRunStatuses
+
+The `useRunStatuses` hook will give you the statuses and overview data of a specific Run.
+
+Loading...
; + } + + if (fetchStatus === "error") { + return ( +{error.name}
+{error.message}
++ {status.label}: {status.state} +
+ //will render the memes as images + {urls?.map((url) =>
+ {JSON.stringify(run.output, null, 2)}
+
+ )}
+ >
+ );
+}
+```
diff --git a/docs/documentation/guides/react-hooks.mdx b/docs/documentation/guides/react-hooks.mdx
index 5df366aa87..cebb7e7a0d 100644
--- a/docs/documentation/guides/react-hooks.mdx
+++ b/docs/documentation/guides/react-hooks.mdx
@@ -1,5 +1,5 @@
---
-title: "React hooks"
+title: "Overview"
description: "How to show the live status of Job Runs in your React app"
---
@@ -9,207 +9,96 @@ You can display the live progress of a Job Run to your users, including the stat
-## Steps
+## Setting up your project for hooks
This guide assumes that your project is already setup and you have a Job running. If not, you should follow the [quick start guide](/documentation/quickstart) first.
-### 1. Install the package
+Runs: {data.runs?.length}
-- Run {run.id}: {run.status} -
-Status: {data.status}
-- Task {task.id}: {task.status} -
-Status: {data.status}
-- Task {task.id}: {task.status} -
-Loading
- ) : error ? ( - JSON.stringify(error, null, 2) - ) : data ? ( -- Event ID: {data.id} -
- ) : ( - - )} - > - ); -} - -export function RunData({ id }: { id: string }) { - const { isLoading, isError, data, error } = useRunDetails(id); - - if (isLoading) { - returnLoading...
; - } - - if (isError) { - returnError
; - } - - if (!data) { - returnLoading...
; - } - - return ( - <> -Status: {task.status}
-Loading...
; } - if (isError) { - returnError
; - } - - if (!data) { - returnLoading...
; + if (fetchStatus === "error") { + return ( +{error.name}
+{error.message}
+{task.icon}
-Status: {task.status}
-Status: {status.state}
+
- {JSON.stringify(data.output, null, 2)}
+ {JSON.stringify(run.output, null, 2)}
)}
>
diff --git a/references/nextjs-reference/src/jobs/edgeCases.ts b/references/nextjs-reference/src/jobs/edgeCases.ts
deleted file mode 100644
index cd7c60b23e..0000000000
--- a/references/nextjs-reference/src/jobs/edgeCases.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { client } from "@/trigger";
-import { Job, eventTrigger } from "@trigger.dev/sdk";
-import { z } from "zod";
-
-client.defineJob({
- id: "test-long-running-cpu",
- name: "Test long running CPU",
- version: "0.0.1",
- trigger: eventTrigger({
- name: "test.cpu",
- schema: z.object({
- iterations: z.number(),
- sleepDuration: z.number(),
- }),
- }),
- run: async (payload, io, ctx) => {
- console.log(`Running run ${ctx.run.id} at ${new Date().toISOString()}`);
-
- for (let i = 0; i < payload.iterations ?? 1; i++) {
- await new Promise((resolve) => setTimeout(resolve, payload.sleepDuration ?? 1000));
- }
-
- console.log(`Finishing run ${ctx.run.id} at ${new Date().toISOString()}`);
- },
-});
diff --git a/references/nextjs-reference/src/jobs/events.ts b/references/nextjs-reference/src/jobs/events.ts
deleted file mode 100644
index 4ef4071864..0000000000
--- a/references/nextjs-reference/src/jobs/events.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-import { client } from "@/trigger";
-import { Job, eventTrigger } from "@trigger.dev/sdk";
-import { z } from "zod";
-
-client.defineJob({
- id: "test-event-trigger-1",
- name: "Test Event Trigger 1",
- version: "0.0.1",
- logLevel: "debug",
- trigger: eventTrigger({
- name: "test-event-trigger-1",
- schema: z.object({
- name: z.string(),
- payload: z.any(),
- }),
- }),
- run: async (payload, io, ctx) => {
- await io.sendEvent(
- "send",
- {
- name: payload.name,
- payload: payload.payload,
- timestamp: new Date(),
- },
- { deliverAt: new Date(Date.now() + 1000 * 30) }
- );
- },
-});
-
-client.defineJob({
- id: "test-event-trigger-2",
- name: "Test Event Trigger 2",
- version: "0.0.1",
- logLevel: "debug",
- trigger: eventTrigger({
- name: "test-event-trigger-2",
- }),
- run: async (payload, io, ctx) => {
- for (let index = 0; index < 100; index++) {
- await io.sendEvent(`send-${index}`, {
- name: "test-event-trigger-1",
- payload: { name: "whatever", payload: { index } },
- });
- }
- },
-});
-
-client.defineJob({
- id: "test-multiple-events",
- name: "Test Multiple Events",
- version: "0.0.1",
- logLevel: "debug",
- trigger: eventTrigger({
- name: ["test.event.1", "test.event.2"],
- examples: [{ id: "test", name: "Test", payload: { name: "test" } }],
- }),
- run: async (payload, io, ctx) => {
- await io.logger.log(`Triggered by the ${ctx.event.name} event`, { ctx });
- },
-});
diff --git a/references/nextjs-reference/src/jobs/general.ts b/references/nextjs-reference/src/jobs/general.ts
deleted file mode 100644
index a35786bf9f..0000000000
--- a/references/nextjs-reference/src/jobs/general.ts
+++ /dev/null
@@ -1,269 +0,0 @@
-import { client, github, githubUser, openai, slack } from "@/trigger";
-import { events } from "@trigger.dev/github";
-import {
- Job,
- cronTrigger,
- eventTrigger,
- intervalTrigger,
- isTriggerError,
- missingConnectionNotification,
- missingConnectionResolvedNotification,
-} from "@trigger.dev/sdk";
-import { z } from "zod";
-
-const enabled = true;
-
-client.defineJob({
- id: "on-missing-auth-connection",
- name: "On missing auth connection",
- version: "0.1.1",
- enabled,
- trigger: missingConnectionNotification([githubUser]),
- integrations: {
- slack,
- },
- run: async (payload, io, ctx) => {
- switch (payload.type) {
- case "DEVELOPER": {
- return await io.slack.postMessage("message", {
- text: `Missing developer connection: ${JSON.stringify(payload)}`,
- channel: "C04GWUTDC3W",
- });
- }
- case "EXTERNAL": {
- return await io.slack.postMessage("message", {
- text: `Missing external connection: account: ${JSON.stringify(
- payload.account
- )}, payload: ${JSON.stringify(payload)}`,
- channel: "C04GWUTDC3W",
- });
- }
- }
- },
-});
-
-client.defineJob({
- id: "on-missing-auth-connection-resolved",
- name: "On missing auth connection-resolved",
- version: "0.1.1",
- enabled,
- trigger: missingConnectionResolvedNotification([githubUser]),
- integrations: {
- slack,
- },
- run: async (payload, io, ctx) => {
- switch (payload.type) {
- case "DEVELOPER": {
- return await io.slack.postMessage("message", {
- text: `Missing developer connection resolved: ${JSON.stringify(payload)}`,
- channel: "C04GWUTDC3W",
- });
- }
- case "EXTERNAL": {
- return await io.slack.postMessage("message", {
- text: `Missing external connection resolved: ${JSON.stringify(payload)}`,
- channel: "C04GWUTDC3W",
- });
- }
- }
- },
-});
-
-client.defineJob({
- id: "get-user-repo",
- name: "Get User Repo",
- version: "0.1.1",
- enabled,
- trigger: eventTrigger({
- name: "get.repo",
- schema: z.object({
- owner: z.string(),
- repo: z.string(),
- }),
- }),
- integrations: {
- github: githubUser,
- },
- run: async (payload, io, ctx) => {
- return await io.github.getRepo("get.repo", payload);
- },
-});
-
-client.defineJob({
- id: "event-1",
- name: "Run when the foo.bar event happens",
- version: "0.0.1",
- enabled: true,
- trigger: eventTrigger({
- name: "foo.bar",
- }),
- run: async (payload, io, ctx) => {
- await io.try(
- async () => {
- return await io.runTask(
- "task-1",
- async (task) => {
- if (task.attempts > 2) {
- return {
- bar: "foo",
- };
- }
-
- throw new Error(`Task failed on ${task.attempts} attempt(s)`);
- },
- { name: "task-1", retry: { limit: 3 } }
- );
- },
- async (error) => {
- // These should never be reached
- await io.wait("wait-after-error", 5);
-
- await io.logger.error("This is a log error message", {
- payload,
- error,
- });
-
- return {
- foo: "bar",
- };
- }
- );
-
- try {
- await io.runTask(
- "task-2",
- async (task) => {
- throw new Error(`Task failed on ${task.attempts} attempt(s)`);
- },
- { name: "task-2", retry: { limit: 5 } }
- );
- } catch (error) {
- if (isTriggerError(error)) {
- throw error;
- }
-
- await io.wait("wait-after-error", 5);
-
- await io.logger.error("This is a log error message", {
- payload,
- error,
- });
- }
-
- return {
- payload,
- };
- },
-});
-
-client.defineJob({
- id: "scheduled-job-1",
- name: "Scheduled Job 1",
- version: "0.1.1",
- enabled: true,
- trigger: intervalTrigger({
- seconds: 60,
- }),
- run: async (payload, io, ctx) => {
- await io.wait("wait", 5); // wait for 5 seconds
-
- await io.logger.info("This is a log info message", {
- payload,
- });
-
- await io.sendEvent("send-event", {
- name: "custom.event",
- payload,
- context: ctx,
- });
-
- await io.runTask("level 1", async () => {
- await io.runTask("level 2", async () => {
- await io.runTask("level 3", async () => {
- await io.runTask("level 4", async () => {
- await io.runTask("level 5", async () => {});
- });
- });
- });
- });
-
- await io.wait("5 minutes", 5 * 60);
-
- await io.runTask("Fingers crossed", async () => {
- throw new Error("You messed up buddy!");
- });
- },
-});
-
-client.defineJob({
- id: "scheduled-job-2",
- name: "Scheduled Job 2",
- version: "0.1.1",
- enabled,
- trigger: cronTrigger({
- cron: "*/5 * * * *", // every 5 minutes
- }),
- run: async (payload, io, ctx) => {
- await io.wait("wait", 5); // wait for 5 seconds
- await io.logger.info("This is a log info message", {
- payload,
- ctx,
- });
-
- return {
- message: "Hello from scheduled job 1",
- };
- },
-});
-
-client.defineJob({
- id: "test-io-functions",
- name: "Test IO functions",
- version: "0.1.1",
- enabled,
- trigger: eventTrigger({
- name: "test.io",
- }),
- run: async (payload, io, ctx) => {
- await io.wait("wait", 5); // wait for 5 seconds
- await io.logger.info("This is a log info message", {
- payload,
- });
- await io.sendEvent("send-event", {
- name: "custom.event",
- payload,
- context: ctx,
- });
- },
-});
-
-client.defineJob({
- id: "alert-on-new-github-issues-3",
- name: "Alert on new GitHub issues",
- version: "0.1.1",
- enabled,
- integrations: {
- slack,
- },
- trigger: github.triggers.repo({
- event: events.onIssueOpened,
- owner: "ericallam",
- repo: "basic-starter-12k",
- }),
- run: async (payload, io, ctx) => {
- await io.runTask("slow task", async () => {
- await new Promise((resolve) => setTimeout(resolve, 5000));
- });
-
- await io.logger.info("This is a simple log info message");
-
- await io.wait("wait", 5); // wait for 5 seconds
-
- const response = await io.slack.postMessage("Slack 📝", {
- text: `New Issue opened: ${payload.issue.html_url}`,
- channel: "C04GWUTDC3W",
- });
-
- return response;
- },
-});
diff --git a/references/nextjs-reference/src/jobs/github.ts b/references/nextjs-reference/src/jobs/github.ts
deleted file mode 100644
index c4aa833b4e..0000000000
--- a/references/nextjs-reference/src/jobs/github.ts
+++ /dev/null
@@ -1,371 +0,0 @@
-import { client, github, slack } from "@/trigger";
-import { Github } from "@trigger.dev/github";
-import { events } from "@trigger.dev/github";
-import { Job } from "@trigger.dev/sdk";
-
-const githubApiKey = new Github({
- id: "github-api-key",
- token: process.env["GITHUB_API_KEY"]!,
-});
-
-client.defineJob({
- id: "github-integration-on-issue",
- name: "GitHub Integration - On Issue",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onIssue,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-issue-opened",
- name: "GitHub Integration - On Issue Opened",
- version: "0.1.0",
- integrations: { github: githubApiKey },
- trigger: githubApiKey.triggers.repo({
- event: events.onIssueOpened,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.github.addIssueAssignees("add assignee", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- issueNumber: payload.issue.number,
- assignees: ["matt-aitken"],
- });
-
- await io.github.addIssueLabels("add label", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- issueNumber: payload.issue.number,
- labels: ["bug"],
- });
-
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "new-github-issue-reminder",
- name: "New GitHub issue reminder",
- version: "0.1.0",
- integrations: { github, slack },
- trigger: github.triggers.repo({
- event: events.onIssueOpened,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- //delay for 24 hours (or 60 seconds in development)
- const delayDuration = ctx.environment.type === "DEVELOPMENT" ? 60 : 60 * 60 * 24;
- await io.wait("wait 24 hours", delayDuration);
-
- const issue = await io.github.getIssue("get issue", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- issueNumber: payload.issue.number,
- });
-
- //if the issue has had no activity
- if (issue.updated_at === payload.issue.updated_at) {
- await io.slack.postMessage("Slack reminder", {
- text: `New issue needs attention: <${issue.html_url}|${issue.title}>`,
- channel: "C04GWUTDC3W",
- });
-
- //assign it to someone, in this case… me
- await io.github.addIssueAssignees("add assignee", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- issueNumber: payload.issue.number,
- assignees: ["ericallam"],
- });
- }
- },
-});
-
-client.defineJob({
- id: "github-integration-on-issue-assigned",
- name: "GitHub Integration - On Issue assigned",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onIssueAssigned,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-issue-commented",
- name: "GitHub Integration - On Issue commented",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onIssueComment,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "star-slack-notification",
- name: "New Star Slack Notification",
- version: "0.1.0",
- integrations: { slack },
- trigger: githubApiKey.triggers.repo({
- event: events.onNewStar,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- const response = await io.slack.postMessage("Slack star", {
- text: `${payload.sender.login} starred ${payload.repository.full_name}.\nTotal: ${payload.repository.stargazers_count}⭐️`,
- channel: "C04GWUTDC3W",
- });
- },
-});
-
-client.defineJob({
- id: "github-integration-on-new-star",
- name: "GitHub Integration - On New Star",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onNewStar,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-new-repo",
- name: "GitHub Integration - On New Repository",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onNewRepository,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-new-branch-or-tag",
- name: "GitHub Integration - On New Branch or Tag",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onNewBranchOrTag,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-new-branch",
- name: "GitHub Integration - On New Branch",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onNewBranch,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-push",
- name: "GitHub Integration - On Push",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onPush,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-pull-request",
- name: "GitHub Integration - On Pull Request",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onPullRequest,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-pull-request-review",
- name: "GitHub Integration - On Pull Request Review",
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onPullRequestReview,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-on-pull-request-merge-commit",
- name: "GitHub Integration - on Pull Request Merge Commit",
- version: "0.1.0",
- integrations: { github },
- trigger: githubApiKey.triggers.repo({
- event: events.onPullRequest,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
-
- if (payload.pull_request.merged && payload.pull_request.merge_commit_sha) {
- const commit = await io.github.getCommit("get merge commit", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- commitSHA: payload.pull_request.merge_commit_sha,
- });
- await io.logger.info("Merge Commit Details", commit);
- }
-
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-get-tree",
- name: "GitHub Integration - Get Tree",
- version: "0.1.0",
- integrations: { github },
- trigger: githubApiKey.triggers.repo({
- event: events.onPullRequest,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
-
- if (payload.pull_request.merged && payload.pull_request.merge_commit_sha) {
- const tree = await io.github.getTree("get merge commit", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- treeSHA: payload.pull_request.merge_commit_sha,
- });
- await io.logger.info("Tree ", tree);
- }
-
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-get-reference",
- name: "GitHub Integration - Get Reference",
- integrations: { github },
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onNewBranch,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
-
- const ref = await io.github.getReference("Get reference", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- ref: payload.ref,
- });
-
- await io.logger.info("Reference ", ref);
-
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-list-matching-references",
- name: "GitHub Integration - List Matching References",
- integrations: { github },
- version: "0.1.0",
- trigger: githubApiKey.triggers.repo({
- event: events.onNewBranch,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
-
- const ref = await io.github.listMatchingReferences("List Matching References", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- ref: payload.ref,
- });
-
- await io.logger.info("Reference ", ref);
-
- return { payload, ctx };
- },
-});
-
-client.defineJob({
- id: "github-integration-get-tag",
- name: "GitHub Integration - Get Tag",
- version: "0.1.0",
- integrations: { github },
- trigger: githubApiKey.triggers.repo({
- event: events.onNewBranchOrTag,
- owner: "triggerdotdev",
- repo: "empty",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("This is a simple log info message");
- if (payload.ref_type === "tag") {
- const tag = io.github.getTag("Get Tag", {
- owner: payload.repository.owner.login,
- repo: payload.repository.name,
- tagSHA: payload.ref,
- });
- await io.logger.info("Tag ", tag);
- }
- return { payload, ctx };
- },
-});
diff --git a/references/nextjs-reference/src/jobs/hooks.ts b/references/nextjs-reference/src/jobs/hooks.ts
index f7a9fd425d..09ed9412ce 100644
--- a/references/nextjs-reference/src/jobs/hooks.ts
+++ b/references/nextjs-reference/src/jobs/hooks.ts
@@ -9,14 +9,64 @@ client.defineJob({
name: "test-event",
}),
run: async (payload, io, ctx) => {
- await io.logger.log("This Job is triggered from a button in the frontend");
- await io.wait("wait", 5);
- await io.logger.log("It runs for a while to test the React hooks");
- await io.wait("wait 2", 5);
- await io.logger.log("This is the end of the job");
-
- return {
- myMessage: "This is the output of the job",
- };
+ const gettingInputData = await io.createStatus("getting-input-data", {
+ label: "Getting input data",
+ // state: "loading",
+ });
+
+ await io.wait("wait-input", 2);
+
+ await gettingInputData.update("input-data-complete", {
+ label: "Input data complete",
+ state: "success",
+ });
+
+ const generatingMemes = await io.createStatus("generating-memes", {
+ label: "Generating memes",
+ state: "loading",
+ data: {
+ progress: 0.1,
+ },
+ });
+
+ await io.wait("wait", 2);
+
+ //...do stuff
+ await generatingMemes.update("middle-generation", {
+ data: {
+ progress: 0.3,
+ urls: [
+ "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZnZoMndsdWh0MmhvY2kyaDF6YjZjZzg1ZGsxdnhhYm13a3Q1Y3lkbyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/13HgwGsXF0aiGY/giphy.gif",
+ ],
+ },
+ });
+
+ await io.wait("wait-again", 4);
+
+ //...do stuff
+ await generatingMemes.update("generating-more-memes", {
+ data: {
+ progress: 0.6,
+ urls: [
+ "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZnZoMndsdWh0MmhvY2kyaDF6YjZjZzg1ZGsxdnhhYm13a3Q1Y3lkbyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/13HgwGsXF0aiGY/giphy.gif",
+ "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbXdhNGhjaXVoZzFrMWJ0dmYyM2ZuOTIxN2J3aWYwY3J1OHI4eW13cCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/scZPhLqaVOM1qG4lT9/giphy.gif",
+ ],
+ },
+ });
+
+ await io.wait("wait-again", 4);
+
+ await generatingMemes.update("completed-generation", {
+ label: "Generated memes",
+ state: "success",
+ data: {
+ progress: 1.0,
+ urls: [
+ "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZnZoMndsdWh0MmhvY2kyaDF6YjZjZzg1ZGsxdnhhYm13a3Q1Y3lkbyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/13HgwGsXF0aiGY/giphy.gif",
+ "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbXdhNGhjaXVoZzFrMWJ0dmYyM2ZuOTIxN2J3aWYwY3J1OHI4eW13cCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/scZPhLqaVOM1qG4lT9/giphy.gif",
+ "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExdHJhdXJ2Nnl6YnR3bXZuejZ3Y3Q5a2w3Mng2ZXZmMmJjeWdtZWhibCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/yYSSBtDgbbRzq/giphy-downsized.gif",
+ ],
+ },
+ });
},
});
diff --git a/references/nextjs-reference/src/jobs/logging.ts b/references/nextjs-reference/src/jobs/logging.ts
deleted file mode 100644
index 3ebd97c5b8..0000000000
--- a/references/nextjs-reference/src/jobs/logging.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { client } from "@/trigger";
-import { Job, eventTrigger } from "@trigger.dev/sdk";
-
-client.defineJob({
- id: "test-logging",
- name: "Test logging",
- version: "0.0.1",
- logLevel: "debug",
- trigger: eventTrigger({
- name: "test.logging",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.log("Hello log level", { payload });
- await io.logger.error("Hello error level", { payload });
- await io.logger.warn("Hello warn level", { payload });
- await io.logger.info("Hello info level", { payload });
- await io.logger.debug("Hello debug level", { payload });
- },
-});
diff --git a/references/nextjs-reference/src/jobs/openai.ts b/references/nextjs-reference/src/jobs/openai.ts
deleted file mode 100644
index cd3219fa5d..0000000000
--- a/references/nextjs-reference/src/jobs/openai.ts
+++ /dev/null
@@ -1,157 +0,0 @@
-import { client } from "@/trigger";
-import { OpenAI } from "@trigger.dev/openai";
-import { Job, eventTrigger } from "@trigger.dev/sdk";
-import { z } from "zod";
-
-const openai = new OpenAI({
- id: "openai",
- apiKey: process.env["OPENAI_API_KEY"]!,
-});
-
-client.defineJob({
- id: "openai-tasks",
- name: "OpenAI Tasks",
- version: "0.0.1",
- trigger: eventTrigger({
- name: "openai.tasks",
- schema: z.object({}),
- }),
- integrations: {
- openai,
- },
- run: async (payload, io, ctx) => {
- const models = await io.openai.listModels("list-models");
-
- if (models.data.length > 0) {
- await io.openai.retrieveModel("get-model", {
- model: models.data[0].id,
- });
- }
-
- await io.openai.backgroundCreateChatCompletion("background-chat-completion", {
- model: "gpt-3.5-turbo",
- messages: [
- {
- role: "user",
- content: "Create a good programming joke about background jobs",
- },
- ],
- });
-
- await io.openai.createChatCompletion("chat-completion", {
- model: "gpt-3.5-turbo",
- messages: [
- {
- role: "user",
- content: "Create a good programming joke about background jobs",
- },
- ],
- });
-
- await io.openai.backgroundCreateCompletion("background-completion", {
- model: "text-davinci-003",
- prompt: "Create a good programming joke about Tasks",
- });
-
- await io.openai.createCompletion("completion", {
- model: "text-davinci-003",
- prompt: "Create a good programming joke about Tasks",
- });
-
- await io.openai.createEdit("edit", {
- model: "text-davinci-edit-001",
- input: "Thsi is ridddled with erors",
- instruction: "Fix the spelling errors",
- });
-
- await io.openai.createEmbedding("embedding", {
- model: "text-embedding-ada-002",
- input: "The food was delicious and the waiter...",
- });
- },
-});
-
-client.defineJob({
- id: "openai-images",
- name: "OpenAI Images",
- version: "0.0.1",
- trigger: eventTrigger({
- name: "openai.images",
- schema: z.object({}),
- }),
- integrations: {
- openai,
- },
- run: async (payload, io, ctx) => {
- await io.openai.createImage("image", {
- prompt: "A hedgehog wearing a party hat",
- n: 2,
- size: "256x256",
- response_format: "url",
- });
- },
-});
-
-client.defineJob({
- id: "openai-files",
- name: "OpenAI Files",
- version: "0.0.1",
- trigger: eventTrigger({
- name: "openai.files",
- schema: z.object({}),
- }),
- integrations: {
- openai,
- },
- run: async (payload, io, ctx) => {
- // jsonl string
- await io.openai.createFile("file-string", {
- file: `{ "prompt": "Tell me a joke", "completion": "Something funny" }\n{ "prompt": "Tell me another joke", "completion": "Something also funny" }`,
- fileName: "cool-file.jsonl",
- purpose: "fine-tune",
- });
-
- // fine tune file
- const fineTuneFile = await io.openai.createFineTuneFile("file-fine-tune", {
- fileName: "fine-tune.jsonl",
- examples: [
- {
- prompt: "Tell me a joke",
- completion: "Why did the chicken cross the road? No one knows",
- },
- {
- prompt: "Tell me another joke",
- completion: "Why did the chicken cross the road? To get to the other side",
- },
- ],
- });
-
- const model = await io.openai.createFineTune("fine-tune", {
- model: "davinci",
- training_file: fineTuneFile.id,
- });
-
- const fineTunes = await io.openai.listFineTunes("list-fine-tunes");
-
- const fineTune = await io.openai.retrieveFineTune("get-fine-tune", {
- fineTuneId: model.id,
- });
-
- const events = await io.openai.listFineTuneEvents("list-fine-tune-events", {
- fineTuneId: model.id,
- });
-
- const cancelFineTune = await io.openai.cancelFineTune("cancel-fine-tune", {
- fineTuneId: model.id,
- });
-
- const files = await io.openai.listFiles("list-files");
- await io.logger.info("files", files);
-
- //this will fail because the fine tune didn't complete
- await io.logger.info("This next task will fail because the model never completed");
- const deleteFineTune = await io.openai.deleteFineTune("delete-fine-tune", {
- fineTunedModelId: model.id,
- });
- },
-});
diff --git a/references/nextjs-reference/src/jobs/plain.ts b/references/nextjs-reference/src/jobs/plain.ts
deleted file mode 100644
index 7eb51b1f8d..0000000000
--- a/references/nextjs-reference/src/jobs/plain.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import { client } from "@/trigger";
-import {
- ComponentDividerSpacingSize,
- ComponentTextColor,
- ComponentTextSize,
- Plain,
-} from "@trigger.dev/plain";
-import { Job, eventTrigger } from "@trigger.dev/sdk";
-
-export const plain = new Plain({
- id: "plain-1",
- apiKey: process.env["PLAIN_API_KEY"]!,
-});
-
-client.defineJob({
- id: "plain-playground",
- name: "Plain Playground",
- version: "0.1.1",
- integrations: {
- plain,
- },
- trigger: eventTrigger({
- name: "plain.playground",
- }),
- run: async (payload, io, ctx) => {
- const { customer } = await io.plain.upsertCustomer("upsert-customer", {
- identifier: {
- emailAddress: "eric@trigger.dev",
- },
- onCreate: {
- email: {
- email: "eric@trigger.dev",
- isVerified: true,
- },
- fullName: "Eric Allam",
- externalId: "123",
- },
- onUpdate: {
- fullName: {
- value: "Eric Allam",
- },
- externalId: {
- value: "123",
- },
- },
- });
-
- const result = await io.plain.runTask("create-issue", async (client) =>
- client.createIssue({
- customerId: "abcdefghij",
- issueTypeId: "123456",
- })
- );
-
- const foundCustomer = await io.plain.getCustomerById("get-customer", {
- customerId: customer.id,
- });
-
- const timelineEntry = await io.plain.upsertCustomTimelineEntry("upsert-timeline-entry", {
- customerId: customer.id,
- title: "My timeline entry",
- components: [
- {
- componentText: {
- text: `This is a nice title`,
- },
- },
- {
- componentDivider: {
- dividerSpacingSize: ComponentDividerSpacingSize.M,
- },
- },
- {
- componentText: {
- textSize: ComponentTextSize.S,
- textColor: ComponentTextColor.Muted,
- text: "External id",
- },
- },
- {
- componentText: {
- text: foundCustomer?.externalId ?? "",
- },
- },
- ],
- });
- },
-});
diff --git a/references/nextjs-reference/src/jobs/schedules.ts b/references/nextjs-reference/src/jobs/schedules.ts
deleted file mode 100644
index d5dc061ebf..0000000000
--- a/references/nextjs-reference/src/jobs/schedules.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { client } from "@/trigger";
-import { Job, cronTrigger } from "@trigger.dev/sdk";
-
-client.defineJob({
- id: "test-cron-schedule-5",
- name: "Test Cron Schedule 5",
- version: "0.0.1",
- logLevel: "debug",
- trigger: cronTrigger({
- cron: "*/1 * * * *",
- }),
- run: async (payload, io, ctx) => {
- await io.logger.debug("Hello cron schedule 2a", {
- payload,
- payload2: payload,
- });
- },
-});
diff --git a/references/nextjs-reference/src/jobs/slack.ts b/references/nextjs-reference/src/jobs/slack.ts
deleted file mode 100644
index 4df5200607..0000000000
--- a/references/nextjs-reference/src/jobs/slack.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-import { client } from "@/trigger";
-import { Slack } from "@trigger.dev/slack";
-import { Job, cronTrigger, eventTrigger } from "@trigger.dev/sdk";
-
-const db = {
- getKpiSummary: async (date: Date) => {
- return {
- revenue: 23_269,
- orders: 1_234,
- };
- },
-};
-
-export const slack = new Slack({ id: "slack-6" });
-export const slackMissing = new Slack({ id: "slack-7" });
-
-client.defineJob({
- id: "slack-kpi-summary",
- name: "Slack kpi summary",
- version: "0.1.1",
- integrations: {
- slack,
- },
- trigger: cronTrigger({
- cron: "0 9 * * *", // 9am every day (UTC)
- }),
- run: async (payload, io, ctx) => {
- const { revenue } = await db.getKpiSummary(payload.ts);
- const response = await io.slack.postMessage("Slack 📝", {
- text: `Yesterday's revenue was $${revenue}`,
- channel: "C04GWUTDC3W",
- });
-
- return response;
- },
-});
-
-client.defineJob({
- id: "slack-auto-join",
- name: "Slack Auto Join",
- version: "0.1.1",
- integrations: {
- slack,
- },
- trigger: eventTrigger({
- name: "slack.auto_join",
- }),
- run: async (payload, io, ctx) => {
- const response = await io.slack.postMessage("Slack 📝", {
- channel: "C05G130TH4G",
- text: "Welcome to the team, Eric!",
- blocks: [
- {
- type: "section",
- text: {
- type: "mrkdwn",
- text: `Welcome to the team, Eric!`,
- },
- },
- {
- type: "section",
- text: {
- type: "mrkdwn",
- text: `I'm here to help you get started with Trigger!`,
- },
- },
- ],
- });
-
- return response;
- },
-});
-
-client.defineJob({
- id: "slack-missing-integration",
- name: "Slack with missing integration",
- version: "0.1.1",
- integrations: {
- slack: slackMissing,
- },
- trigger: eventTrigger({
- name: "missing.integration",
- }),
- run: async (payload, io, ctx) => {
- const response = await io.slack.postMessage("message", {
- text: `There's no Slack connection, or is there?`,
- channel: "C04GWUTDC3W",
- });
-
- return response;
- },
-});
diff --git a/references/nextjs-reference/src/jobs/stripe.ts b/references/nextjs-reference/src/jobs/stripe.ts
deleted file mode 100644
index df834b82a3..0000000000
--- a/references/nextjs-reference/src/jobs/stripe.ts
+++ /dev/null
@@ -1,160 +0,0 @@
-import { Stripe } from "@trigger.dev/stripe";
-import { client } from "@/trigger";
-import { eventTrigger } from "@trigger.dev/sdk";
-import { z } from "zod";
-
-const stripe = new Stripe({
- id: "stripe",
- apiKey: process.env["STRIPE_API_KEY"]!,
-});
-
-client.defineJob({
- id: "stripe-example-1",
- name: "Stripe Example 1",
- version: "0.1.0",
- trigger: eventTrigger({
- name: "stripe.example",
- schema: z.object({
- customerId: z.string(),
- source: z.string(),
- }),
- }),
- integrations: {
- stripe,
- },
- run: async (payload, io, ctx) => {
- await io.stripe.createCharge("create-charge", {
- amount: 100,
- currency: "usd",
- source: payload.source,
- customer: payload.customerId,
- });
- },
-});
-
-client.defineJob({
- id: "stripe-example-1",
- name: "Stripe Example 1",
- version: "0.1.0",
- trigger: eventTrigger({
- name: "stripe.example",
- schema: z.object({
- customerId: z.string(),
- source: z.string(),
- }),
- }),
- integrations: {
- stripe,
- },
- run: async (payload, io, ctx) => {
- await io.stripe.createCharge("create-charge", {
- amount: 100,
- currency: "usd",
- source: payload.source,
- customer: payload.customerId,
- });
- },
-});
-
-client.defineJob({
- id: "stripe-create-customer",
- name: "Stripe Create Customer",
- version: "0.1.0",
- trigger: eventTrigger({
- name: "stripe.new.customer",
- schema: z.object({
- email: z.string(),
- name: z.string(),
- }),
- }),
- integrations: {
- stripe,
- },
- run: async (payload, io, ctx) => {
- await io.stripe.createCustomer("create-customer", {
- email: payload.email,
- name: payload.name,
- });
- },
-});
-
-client.defineJob({
- id: "stripe-update-customer",
- name: "Stripe Update Customer",
- version: "0.1.0",
- trigger: eventTrigger({
- name: "stripe.update.customer",
- schema: z.object({
- customerId: z.string(),
- name: z.string(),
- }),
- }),
- integrations: {
- stripe,
- },
- run: async (payload, io, ctx) => {
- await io.stripe.updateCustomer("update-customer", {
- id: payload.customerId,
- name: payload.name,
- });
- },
-});
-
-client.defineJob({
- id: "stripe-retrieve-subscription",
- name: "Stripe Retrieve Subscription",
- version: "0.1.0",
- trigger: eventTrigger({
- name: "stripe.retrieve.subscription",
- schema: z.object({
- id: z.string(),
- }),
- }),
- integrations: {
- stripe,
- },
- run: async (payload, io, ctx) => {
- const subscription = await io.stripe.retrieveSubscription("get", {
- id: payload.id,
- expand: ["customer"],
- });
- },
-});
-
-client.defineJob({
- id: "stripe-on-price",
- name: "Stripe On Price",
- version: "0.1.0",
- trigger: stripe.onPrice({ events: ["price.created", "price.updated"] }),
- run: async (payload, io, ctx) => {
- if (ctx.event.name === "price.created") {
- await io.logger.info("price created!", { ctx });
- } else {
- await io.logger.info("price updated!", { ctx });
- }
- },
-});
-
-client.defineJob({
- id: "stripe-on-price-created",
- name: "Stripe On Price Created",
- version: "0.1.0",
- trigger: stripe.onPriceCreated(),
- run: async (payload, io, ctx) => {
- await io.logger.info("ctx", { ctx });
- },
-});
-
-client.defineJob({
- id: "stripe-on-subscription-created",
- name: "Stripe On Subscription Created",
- version: "0.1.0",
- trigger: stripe.onCustomerSubscriptionCreated({
- filter: {
- currency: ["usd"],
- },
- }),
- run: async (payload, io, ctx) => {
- await io.logger.info("ctx", { ctx });
- },
-});
diff --git a/references/nextjs-reference/src/jobs/supabase.ts b/references/nextjs-reference/src/jobs/supabase.ts
deleted file mode 100644
index 0b93b3c37a..0000000000
--- a/references/nextjs-reference/src/jobs/supabase.ts
+++ /dev/null
@@ -1,341 +0,0 @@
-import { Database } from "@/supabase.types";
-import { client } from "@/trigger";
-import {
- type IntegrationIO,
- Job,
- eventTrigger,
- type JobPayload,
- type JobIO,
- type TriggerPayload,
- type IOWithIntegrations,
-} from "@trigger.dev/sdk";
-import { SupabaseManagement, Supabase } from "@trigger.dev/supabase";
-import { z } from "zod";
-
-const supabase = new SupabaseManagement({
- id: "supabase",
-});
-
-const db = supabase.db