diff --git a/docs/triggering.mdx b/docs/triggering.mdx index c20565f556..0765a51072 100644 --- a/docs/triggering.mdx +++ b/docs/triggering.mdx @@ -74,17 +74,19 @@ export async function POST(request: Request) { ```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.