Skip to content

Update remix examples #1303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions docs/triggering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof emailSequence>("email-sequence", {
to: data.email,
name: data.name,
});
Expand Down Expand Up @@ -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<typeof emailSequence>(
"email-sequence",
data.users.map((u) => ({ payload: { to: u.email, name: u.name } }))
);

//return a success response with the handle
return json(batchHandle);
}
```

</CodeGroup>

### tasks.triggerAndPoll()
Expand Down Expand Up @@ -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<typeof emailSequence>(
"email-sequence",
{
to: data.email,
name: data.name,
},
{ pollIntervalMs: 5000 }
);

//return a success response with the result
return json(result);
}
```
</CodeGroup>

<Note>
Expand Down Expand Up @@ -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.
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.
Loading