What’s new in v4, how to migrate, and breaking changes.
Feature | Description |
---|---|
Wait for token | Create and wait for tokens to be completed, enabling approval workflows and waiting for arbitrary external conditions. |
Wait idempotency | Skip waits if the same idempotency key is used again when using wait for, wait until, or wait for token. |
Priority | Specify a priority when triggering a task. |
Global lifecycle hooks | Register global lifecycle hooks that are executed for all runs, regardless of the task. |
onWait and onResume | Run code when a run is paused or resumed because of a wait. |
onComplete | Run code when a run completes, regardless of whether it succeeded or failed. |
onCancel | Run code when a run is cancelled. |
Hidden tasks | Create tasks that are not exported from your trigger files but can still be executed. |
Middleware & locals | The middleware system runs at the top level, executing before and after all lifecycle hooks. The locals API allows sharing data between middleware and hooks. |
useWaitToken | Use the useWaitToken hook to complete a wait token from a React component. |
ai.tool | Create an AI tool from an existing schemaTask to use with the Vercel AI SDK. |
21.7.3
21.7.3
trigger dev
CLI command and test your tasks locally, fixing any breaking changes.Copy paste this prompt in full
@trigger.dev/sdk/v3
import path and moved to a new path:handleError
hook to catchError
. Use this instead of handleError
.init
was previously used to initialize data used in the run function. This is the old version:toolTask
function and replaced it with the ai.tool
function, which creates an AI tool from an existing schemaTask
. This is the old version:queue
function. You can no longer create queues “on-demand” when triggering tasks. This is the old version:batchTrigger
function no longer returns runs directly. This is the old version:@trigger.dev/*
packages to a 4.x
version.
@trigger.dev/sdk/v3
import path and moved to a new path:
handleError
and init
handleError
hook to catchError
to better reflect that it can catch and react to errors. handleError
will be removed in a future version.
init
was previously used to initialize data used in the run function:
locals
API and middleware. See the Improved middleware and locals section for more details.
toolTask
function, which created both a Trigger.dev task and a tool compatible with the Vercel AI SDK:
toolTask
function with the ai.tool
function, which creates an AI tool from an existing schemaTask
. See the ai.tool page for more details.
queue
function:
concurrencyLimit
when a run is paused. You can go back to the previous behavior by setting the releaseConcurrencyOnWaitpoint
option to true
on the queue:
wait.for({ seconds: 10 })
)myTask.triggerAndWait()
, myTask.batchTriggerAndWait([...])
)wait.forToken(tokenId)
)ctx
object:
ctx.attempt.id
and ctx.attempt.status
have been removed. ctx.attempt.number
is still available.ctx.task.exportName
has been removed (since we no longer require tasks to be exported to be triggered).batchTrigger
function no longer returns a runs
list directly. In v3, you could access the runs directly from the batch handle:
runs.list()
method to get the list of runs: