From d4afafe28e51af3e1c556154edd9d63f0c88df7c Mon Sep 17 00:00:00 2001 From: Jacob Paris Date: Sun, 15 Sep 2024 05:22:59 -0400 Subject: [PATCH 1/2] Update remix examples --- docs/triggering.mdx | 63 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/docs/triggering.mdx b/docs/triggering.mdx index c20565f556..0095625668 100644 --- a/docs/triggering.mdx +++ b/docs/triggering.mdx @@ -72,19 +72,21 @@ export async function POST(request: Request) { } ``` -```ts Remix +```ts Remix import { tasks } from "@trigger.dev/sdk/v3"; +import type { emailSequence } from "~/trigger/emails"; +// 👆 **type-only** import export async function action({ request, params }: ActionFunctionArgs) { - if (request.method.toUpperCase() !== "POST") { - return json("Method Not Allowed", { status: 405 }); + if (request.method !== "POST") { + throw new Response("Method Not Allowed", { status: 405 }); } //get the JSON from the request const data = await request.json(); - // The generic argument is optional, but recommended for full type checking - const handle = await tasks.trigger("email-sequence", { + // Pass the task type to `trigger()` as a generic argument, giving you full type checking + const handle = await tasks.trigger("email-sequence", { to: data.email, name: data.name, }); @@ -127,6 +129,29 @@ export async function POST(request: Request) { } ``` +```ts Remix +import { tasks } from "@trigger.dev/sdk/v3"; +import type { emailSequence } from "~/trigger/emails"; + +export async function action({ request, params }: ActionFunctionArgs) { + if (request.method !== "POST") { + throw new Response("Method Not Allowed", { status: 405 }); + } + + //get the JSON from the request + const data = await request.json(); + + // Pass the task type to `batchTrigger()` as a generic argument, giving you full type checking + const batchHandle = await tasks.batchTrigger( + "email-sequence", + data.users.map((u) => ({ payload: { to: u.email, name: u.name } })) + ); + + //return a success response with the handle + return json(batchHandle); +} +``` + ### tasks.triggerAndPoll() @@ -163,6 +188,32 @@ export async function POST(request: Request) { } ``` +```ts Remix +import { tasks } from "@trigger.dev/sdk/v3"; +import type { emailSequence } from "~/trigger/emails"; + +export async function action({ request, params }: ActionFunctionArgs) { + if (request.method !== "POST") { + throw new Response("Method Not Allowed", { status: 405 }); + } + + //get the JSON from the request + const data = await request.json(); + + // Pass the task type to `triggerAndPoll()` as a generic argument, giving you full type checking + const result = await tasks.triggerAndPoll( + "email-sequence", + { + to: data.email, + name: data.name, + }, + { pollIntervalMs: 5000 } + ); + + //return a success response with the result + return json(result); +} +``` @@ -705,4 +756,4 @@ export const myTask = task({ ### Batch Triggering -When using `batchTrigger` or `batchTriggerAndWait`, the total size of all payloads cannot exceed 10MB. This means if you are doing a batch of 100 runs, each payload should be less than 100KB. \ No newline at end of file +When using `batchTrigger` or `batchTriggerAndWait`, the total size of all payloads cannot exceed 10MB. This means if you are doing a batch of 100 runs, each payload should be less than 100KB. From 16e8cf5058c6eed32557c27e58b2caf574175034 Mon Sep 17 00:00:00 2001 From: Jacob Paris Date: Sun, 15 Sep 2024 05:23:41 -0400 Subject: [PATCH 2/2] fix: remove trailing space --- docs/triggering.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/triggering.mdx b/docs/triggering.mdx index 0095625668..0765a51072 100644 --- a/docs/triggering.mdx +++ b/docs/triggering.mdx @@ -72,7 +72,7 @@ export async function POST(request: Request) { } ``` -```ts Remix +```ts Remix import { tasks } from "@trigger.dev/sdk/v3"; import type { emailSequence } from "~/trigger/emails"; // 👆 **type-only** import