Skip to content

Commit cfe0abd

Browse files
authored
Update remix examples (#1303)
* Update remix examples * fix: remove trailing space
1 parent c1690bd commit cfe0abd

File tree

1 file changed

+56
-5
lines changed

1 file changed

+56
-5
lines changed

docs/triggering.mdx

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ export async function POST(request: Request) {
7474

7575
```ts Remix
7676
import { tasks } from "@trigger.dev/sdk/v3";
77+
import type { emailSequence } from "~/trigger/emails";
78+
// 👆 **type-only** import
7779

7880
export async function action({ request, params }: ActionFunctionArgs) {
79-
if (request.method.toUpperCase() !== "POST") {
80-
return json("Method Not Allowed", { status: 405 });
81+
if (request.method !== "POST") {
82+
throw new Response("Method Not Allowed", { status: 405 });
8183
}
8284

8385
//get the JSON from the request
8486
const data = await request.json();
8587

86-
// The generic argument is optional, but recommended for full type checking
87-
const handle = await tasks.trigger("email-sequence", {
88+
// Pass the task type to `trigger()` as a generic argument, giving you full type checking
89+
const handle = await tasks.trigger<typeof emailSequence>("email-sequence", {
8890
to: data.email,
8991
name: data.name,
9092
});
@@ -127,6 +129,29 @@ export async function POST(request: Request) {
127129
}
128130
```
129131

132+
```ts Remix
133+
import { tasks } from "@trigger.dev/sdk/v3";
134+
import type { emailSequence } from "~/trigger/emails";
135+
136+
export async function action({ request, params }: ActionFunctionArgs) {
137+
if (request.method !== "POST") {
138+
throw new Response("Method Not Allowed", { status: 405 });
139+
}
140+
141+
//get the JSON from the request
142+
const data = await request.json();
143+
144+
// Pass the task type to `batchTrigger()` as a generic argument, giving you full type checking
145+
const batchHandle = await tasks.batchTrigger<typeof emailSequence>(
146+
"email-sequence",
147+
data.users.map((u) => ({ payload: { to: u.email, name: u.name } }))
148+
);
149+
150+
//return a success response with the handle
151+
return json(batchHandle);
152+
}
153+
```
154+
130155
</CodeGroup>
131156

132157
### tasks.triggerAndPoll()
@@ -163,6 +188,32 @@ export async function POST(request: Request) {
163188
}
164189
```
165190

191+
```ts Remix
192+
import { tasks } from "@trigger.dev/sdk/v3";
193+
import type { emailSequence } from "~/trigger/emails";
194+
195+
export async function action({ request, params }: ActionFunctionArgs) {
196+
if (request.method !== "POST") {
197+
throw new Response("Method Not Allowed", { status: 405 });
198+
}
199+
200+
//get the JSON from the request
201+
const data = await request.json();
202+
203+
// Pass the task type to `triggerAndPoll()` as a generic argument, giving you full type checking
204+
const result = await tasks.triggerAndPoll<typeof emailSequence>(
205+
"email-sequence",
206+
{
207+
to: data.email,
208+
name: data.name,
209+
},
210+
{ pollIntervalMs: 5000 }
211+
);
212+
213+
//return a success response with the result
214+
return json(result);
215+
}
216+
```
166217
</CodeGroup>
167218

168219
<Note>
@@ -705,4 +756,4 @@ export const myTask = task({
705756

706757
### Batch Triggering
707758

708-
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.
759+
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.

0 commit comments

Comments
 (0)