You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`tasks.trigger()`| Anywhere | Triggers a task and gets a handle you can use to fetch and manage the run. [Read more](#tasks-trigger)|
11
-
|`tasks.batchTrigger()`| Anywhere | Triggers a task multiple times and gets a handle you can use to fetch and manage the runs. [Read more](#tasks-batchtrigger)|
12
-
|`tasks.triggerAndPoll()`| Anywhere | Triggers a task and then polls the run until it’s complete. [Read more](#tasks-triggerandpoll)|
|`tasks.trigger()`| Anywhere | Triggers a task and gets a handle you can use to fetch and manage the run. [Read more](#tasks-trigger)|
11
+
|`tasks.batchTrigger()`| Anywhere | Triggers a task multiple times and gets a handle you can use to fetch and manage the runs. [Read more](#tasks-batchtrigger)|
12
+
|`tasks.triggerAndPoll()`| Anywhere | Triggers a task and then polls the run until it’s complete. [Read more](#tasks-triggerandpoll)|
|`yourTask.trigger()`| Anywhere | Triggers a task and gets a handle you can use to monitor and manage the run. It does not wait for the result. [Read more](#task-trigger)|
19
-
|`yourTask.batchTrigger()`| Anywhere | Triggers a task multiple times and gets a handle you can use to monitor and manage the runs. It does not wait for the results. [Read more](#task-batchtrigger)|
20
-
|`yourTask.triggerAndWait()`| Inside task | Triggers a task and then waits until it's complete. You get the result data to continue with. [Read more](#task-triggerandwait)|
21
-
|`yourTask.batchTriggerAndWait()`| Inside task | Triggers a task multiple times in parallel and then waits until they're all complete. You get the resulting data to continue with. [Read more](#task-batchtriggerandwait)|
|`yourTask.trigger()`| Anywhere | Triggers a task and gets a handle you can use to monitor and manage the run. It does not wait for the result. [Read more](#task-trigger)|
19
+
|`yourTask.batchTrigger()`| Anywhere | Triggers a task multiple times and gets a handle you can use to monitor and manage the runs. It does not wait for the results. [Read more](#task-batchtrigger)|
20
+
|`yourTask.triggerAndWait()`| Inside task | Triggers a task and then waits until it's complete. You get the result data to continue with. [Read more](#task-triggerandwait)|
21
+
|`yourTask.batchTriggerAndWait()`| Inside task | Triggers a task multiple times in parallel and then waits until they're all complete. You get the resulting data to continue with. [Read more](#task-batchtriggerandwait)|
22
22
23
23
Additionally, [scheduled tasks](/tasks-scheduled) get **automatically** triggered on their schedule and webhooks when receiving a webhook.
24
24
@@ -46,7 +46,9 @@ You can use Next.js Server Actions but [you need to be careful with bundling](/g
46
46
Triggers a single run of a task with the payload you pass in, and any options you specify, without needing to import the task.
47
47
48
48
<Note>
49
-
By using `tasks.trigger()`, you can pass in the task type as a generic argument, giving you full type checking. Make sure you use a `type` import so that your task code is not imported into your application.
49
+
By using `tasks.trigger()`, you can pass in the task type as a generic argument, giving you full
50
+
type checking. Make sure you use a `type` import so that your task code is not imported into your
Triggers multiples runs of a task with the payloads you pass in, and any options you specify, without needing to import the task.
104
106
105
107
<Note>
106
-
By using `tasks.batchTrigger()`, you can pass in the task type as a generic argument, giving you full type checking. Make sure you use a `type` import so that your task code is not imported into your application.
108
+
By using `tasks.batchTrigger()`, you can pass in the task type as a generic argument, giving you
109
+
full type checking. Make sure you use a `type` import so that your task code is not imported into
Triggers a single run of a task with the payload you pass in, and any options you specify, and then polls the run until it's complete.
160
164
161
165
<Note>
162
-
By using `tasks.triggerAndPoll()`, you can pass in the task type as a generic argument, giving you full type checking. Make sure you use a `type` import so that your task code is not imported into your application.
166
+
By using `tasks.triggerAndPoll()`, you can pass in the task type as a generic argument, giving you
167
+
full type checking. Make sure you use a `type` import so that your task code is not imported into
When using `batchTriggerAndWait`, you have full control over how to handle failures within the batch. The method returns an array of run results, allowing you to inspect each run's outcome individually and implement custom error handling.
381
439
382
-
Here's how you can manage run failures:
440
+
Here's how you can manage run failures:
441
+
442
+
1.**Inspect individual run results**: Each run in the returned array has an `ok` property indicating success or failure.
383
443
384
-
1.**Inspect individual run results**: Each run in the returned array has an `ok` property indicating success or failure.
444
+
2.**Access error information**: For failed runs, you can examine the `error` property to get details about the failure.
385
445
386
-
2.**Access error information**: For failed runs, you can examine the `error` property to get details about the failure.
446
+
3.**Choose your failure strategy**: You have two main options:
387
447
388
-
3.**Choose your failure strategy**: You have two main options:
389
-
-**Fail the entire batch**: Throw an error if any run fails, causing the parent task to reattempt.
390
-
-**Continue despite failures**: Process the results without throwing an error, allowing the parent task to continue.
448
+
-**Fail the entire batch**: Throw an error if any run fails, causing the parent task to reattempt.
449
+
-**Continue despite failures**: Process the results without throwing an error, allowing the parent task to continue.
391
450
392
-
4.**Implement custom logic**: You can create sophisticated handling based on the number of failures, types of errors, or other criteria.
451
+
4.**Implement custom logic**: You can create sophisticated handling based on the number of failures, types of errors, or other criteria.
393
452
394
-
Here's an example of how you might handle run failures:
453
+
Here's an example of how you might handle run failures:
395
454
396
455
<CodeGroup>
397
456
398
457
```ts /trigger/batchTriggerAndWait.ts
399
-
const result =awaitbatchChildTask.batchTriggerAndWait([
400
-
{ payload: "item1" },
401
-
{ payload: "item2" },
402
-
{ payload: "item3" },
403
-
]);
404
-
405
-
// Result will contain the finished runs.
406
-
// They're only finished if they have succeeded or failed.
407
-
// "Failed" means all attempts failed
408
-
409
-
for (const run ofresult.runs) {
410
-
411
-
// Check if the run succeeded
412
-
if (run.ok) {
413
-
logger.info("Batch task run succeeded", { output: run.output });
414
-
} else {
415
-
logger.error("Batch task run error", { error: run.error });
458
+
const result =awaitbatchChildTask.batchTriggerAndWait([
459
+
{ payload: "item1" },
460
+
{ payload: "item2" },
461
+
{ payload: "item3" },
462
+
]);
463
+
464
+
// Result will contain the finished runs.
465
+
// They're only finished if they have succeeded or failed.
466
+
// "Failed" means all attempts failed
467
+
468
+
for (const run ofresult.runs) {
469
+
// Check if the run succeeded
470
+
if (run.ok) {
471
+
logger.info("Batch task run succeeded", { output: run.output });
472
+
} else {
473
+
logger.error("Batch task run error", { error: run.error });
416
474
417
-
//You can choose if you want to throw an error and fail the entire run
418
-
thrownewError(`Fail the entire run because ${run.id} failed`);
419
-
}
475
+
//You can choose if you want to throw an error and fail the entire run
476
+
thrownewError(`Fail the entire run because ${run.id} failed`);
0 commit comments