What’s new in v4, how to upgrade, and breaking changes.
21.7.3
21.7.3
wait.createToken
function:
idempotencyKeyTTL
allows you to specify how long the idempotency key should be valid for. The default is 30 days.
10
, the run will win over runs with a priority of 0
that were triggered within the last 10 seconds. A more concrete example:
trigger.config.ts
file, but now you can register them anywhere in your codebase:
init.ts
init.ts
file at the root of your trigger directory, it will be automatically loaded when a task is executed. This is useful if you want to register global lifecycle hooks, or initialize a database connection, etc.
onCancel
hook that is called when a run is cancelled. This is useful if you want to clean up any resources that were allocated for the run.
onCancel
hook along with the signal
passed into the run function to interrupt a call to an external service, for example using the streamText function from the AI SDK:
onCancel
hook can optionally wait for the run
function to finish, and access the output of the run:
runPromise
in the onCancel
hook. After that
point the process will be killed.run
function, but now we’ve hoisted it to the top level and it now runs before/after all the other hooks.
We’ve also added a new locals
API that allows you to share data between middleware and hooks.
run
function and all your hooks (global or task specific) you can access the database client using getDb()
:
useWaitToken
react hook that allows you to complete a wait token from a React component, using a Public Access Token.
useWaitToken
hook in your frontend code:
ai.tool
ai.tool
function that allows you to create an AI tool from an existing schemaTask
to use with the Vercel AI SDK:
experimental_toToolResultContent
option to the ai.tool
function to customize the content of the tool result:
ai.currentToolOptions()
function:
ai.tool
is compatible with schemaTask
’s defined with Zod and ArkType schemas, or any schemas
that implement a .toJsonSchema()
function.trigger dev
CLI command and test your tasks locally, fixing any breaking changes.v4-beta
tag.
@trigger.dev/*
packages. v4-beta
version of the trigger.dev
CLI package:
@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 section for more details.
queue
function:
concurrencyLimit
of 1, you can only have exactly 1 run executing at a time, but you may have more than 1 run in the WAITING
state that belongs to that queue. Runs are only transitioned to the WAITING
state when they are waiting on a waitpoint and have been checkpointed.
PENDING_VERSION
: Task is waiting for a version update because it cannot execute without additional information (task, queue, etc.).QUEUED
: Task is waiting to be executed by a worker.DEQUEUED
: Task has been dequeued and is being sent to a worker to start executing.EXECUTING
: Task is currently being executed by a worker.WAITING
: Task has been paused by the system, and will be resumed by the system.COMPLETED
: Task has been completed successfully.CANCELED
: Task has been canceled by the user.FAILED
: Task has failed to complete, due to an error in the task code.CRASHED
: Task has crashed and won’t be retried, most likely the worker ran out of resources, e.g. memory or storage.SYSTEM_FAILURE
: Task has failed to complete, due to an error in the systemDELAYED
: Task has been scheduled to run at a specific time.EXPIRED
: Task has expired and won’t be executed,TIMED_OUT
: Task has reached its maxDuration and has been stopped.WAITING_FOR_DEPLOY
: This is no longer used, and is replaced by PENDING_VERSION
FROZEN
: This is no longer used, and is replaced by WAITING
INTERRUPTED
: This is no longer usedREATTEMPTING
: This is no longer used, and is replaced by EXECUTING
isQueued
: Returns true when the status is QUEUED
, PENDING_VERSION
, or DELAYED
isExecuting
: Returns true when the status is EXECUTING
, DEQUEUED
. These count against your concurrency limits.isWaiting
: Returns true when the status is WAITING
. These do not count against your concurrency limits.isCompleted
: Returns true when the status is any of the completed statuses.isCanceled
: Returns true when the status is CANCELED
isFailed
: Returns true when the status is any of the failed statuses.isSuccess
: Returns true when the status is COMPLETED
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:
keepNames
(#2091) and
minify
options (experimental) (#2091).
Added experimental_autoDetectExternal
trigger config option
(#2083) and output esbuild metafile,
which can be inspected after deploy --dry run
(#2087).syncEnvVars
for
non-preview deployments (#2131).--self-hosted
flag is no longer required, and enhanced deployment error reporting and image digest retrieval
(#2138). Updated profile switcher
(#2150).processKeepAlive
option, which allows you to
keep the process alive after the run has completed for the next warm start, which makes warm starts even faster.Currently during a warm start, we still recreate the actual task run process between runs, leading to a completely fresh global environment for each run. This experimental option will keep the task run process alive between run executions, leading to even faster warm starts. This option is respected in both the dev
CLI and in deployed tasks.To enable this option, add this to your trigger.config.ts
:experimental_processKeepAlive
to provide more options:run
function of a task.node-22
runtime now uses v22.16.0 and bun
uses the latest v1.2.18 release. The default node
runtime is unchanged and points at v21.7.3. (#2254)
TRIGGER_ACCESS_TOKEN
and add useful error message with link to docs (#2258)
releaseConcurrencyOnWaitpoint
option on queues and the releaseConcurrency
option on various wait functions. Replaced with the following default behavior: (#2284)
PENDING_VERSION
: Task is waiting for a version update because it cannot execute without additional information (task, queue, etc.)QUEUED
: Task is waiting to be executed by a workerDEQUEUED
: Task has been dequeued and is being sent to a worker to start executing.EXECUTING
: Task is currently being executed by a workerWAITING
: Task has been paused by the system, and will be resumed by the systemCOMPLETED
: Task has been completed successfullyCANCELED
: Task has been canceled by the userFAILED
: Task has failed to complete, due to an error in the systemCRASHED
: Task has crashed and won’t be retried, most likely the worker ran out of resources, e.g. memory or storageSYSTEM_FAILURE
: Task has failed to complete, due to an error in the systemDELAYED
: Task has been scheduled to run at a specific timeEXPIRED
: Task has expired and won’t be executedTIMED_OUT
: Task has reached it’s maxDuration and has been stoppedWAITING_FOR_DEPLOY
: This is no longer used, and is replaced by PENDING_VERSION
FROZEN
: This is no longer used, and is replaced by WAITING
INTERRUPTED
: This is no longer usedREATTEMPTING
: This is no longer used, and is replaced by EXECUTING
isQueued
: Returns true when the status is QUEUED
, PENDING_VERSION
, or DELAYED
isExecuting
: Returns true when the status is EXECUTING
, DEQUEUED
. These count against your concurrency limits.isWaiting
: Returns true when the status is WAITING
. These do not count against your concurrency limits.isCompleted
: Returns true when the status is any of the completed statuses.isCanceled
: Returns true when the status is CANCELED
isFailed
: Returns true when the status is any of the failed statuses.isSuccess
: Returns true when the status is COMPLETED
EXECUTING
or DEQUEUED
.