Tasks need to be triggered in order to run.
Function | What it does | |
---|---|---|
tasks.trigger() | Triggers a task and returns a handle you can use to fetch and manage the run. | Docs |
tasks.batchTrigger() | Triggers a single task in a batch and returns a handle you can use to fetch and manage the runs. | Docs |
tasks.triggerAndPoll() | Triggers a task and then polls the run until it’s complete. | Docs |
batch.trigger() | Similar to tasks.batchTrigger but allows running multiple different tasks | Docs |
Function | What it does | |
---|---|---|
yourTask.trigger() | Triggers a task and gets a handle you can use to monitor and manage the run. It does not wait for the result. | Docs |
yourTask.batchTrigger() | 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. | Docs |
yourTask.triggerAndWait() | Triggers a task and then waits until it’s complete. You get the result data to continue with. | Docs |
yourTask.batchTriggerAndWait() | Triggers a task multiple times in parallel and then waits until they’re all complete. You get the resulting data to continue with. | Docs |
batch.triggerAndWait() | Similar to batch.trigger but will wait on the triggered tasks to finish and return the results. | Docs |
batch.triggerByTask() | Similar to batch.trigger but allows passing in task instances instead of task IDs. | Docs |
batch.triggerByTaskAndWait() | Similar to batch.triggerbyTask but will wait on the triggered tasks to finish and return the results. | Docs |
TRIGGER_SECRET_KEY
environment variable. If you’re using a preview branch, you also need to set the TRIGGER_PREVIEW_BRANCH
environment variable. You can find the value on the API keys page in the Trigger.dev dashboard. More info on API keys.
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.batchTrigger
function using the second argument:
triggerAndPoll()
, especially inside a web request, as it will block the
request until the run is complete. Please see our Realtime docs for a better way to
handle this.trigger()
on a task in a loop, use
batchTrigger()
instead which will trigger up to 500 runs in a single
call.batchTrigger
, you can use the second argument:
Don't use this in parallel, e.g. with `Promise.all()`
batchTriggerAndWait()
if you can, or a for loop if you can’t.To control concurrency using batch triggers, you can set queue.concurrencyLimit
on the child task.result
object is a “Result” type that needs to be checked to see if the child task run was successful:
unwrap
method:
Don't use this in parallel, e.g. with `Promise.all()`
maxConcurrency
. Alternatively, use sequentially with a for loop.To control concurrency, you can set queue.concurrencyLimit
on the child task.How to handle run failures
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.Here’s how you can manage run failures:ok
property indicating success or failure.
error
property to get details about the failure.
delay
delay
option:
runs.cancel
SDK function:
runs.reschedule
SDK function:
delay
option is also available when using batchTrigger
:
ttl
ttl
of 10 minutes. You can disable this by setting the
ttl
option.delay
and ttl
, the TTL will start counting down from the time the run is enqueued, not from the time the run is triggered.
So for example, when using the following code:
ttl
option only accepts durations and not absolute timestamps.
idempotencyKey
idempotencyKey
to ensure that a task is only triggered once with the same key. This is useful if you are triggering a task within another task that might be retried:
idempotencyKey
option is not available when using
triggerAndWait
or batchTriggerAndWait
, due to a bug that would sometimes cause the parent task
to become stuck. We are working on a fix for this issue.idempotencyKeyTTL
queue
concurrencyKey
concurrencyKey
. It creates a separate queue for each value of the key.
Your backend code:
maxAttempts
retry.maxAttempts
value set in the task definition.
tags
metadata
maxDuration
payloadPresignedUrl
from the runs.retrieve
SDK function so you can download the payload if needed:
outputPresignedUrl
. Task outputs are limited to 100MB.