Context (ctx
) is a way to get information about a run.
The context object does not change whilst your code is executing. This means values like ctx.run.durationMs
will be fixed at the moment the run()
function is called.
import { task } from "@trigger.dev/sdk/v3" ;
export const parentTask = task ({
id: "parent-task" ,
run : async ( payload : { message : string }, { ctx }) => {
if ( ctx . environment . type === "DEVELOPMENT" ) {
return ;
}
},
});
Context properties
The exported function name of the task e.g. myTask
if you defined it like this: export const myTask = task(...)
.
The file path of the task.
The ID of the execution attempt.
The start time of the attempt.
The ID of the background worker.
The ID of the background worker task.
The current status of the attempt.
The context of the task run.
An array of tags associated with the task run. The creation time of the task run.
The start time of the task run.
The duration of the task run in milliseconds when the run()
function is called. For live values use the usage SDK functions . The cost of the task run in cents when the run()
function is called. For live values use the usage SDK functions . The base cost of the task run in cents when the run()
function is called. For live values use the usage SDK functions .
The ID of the environment.
The slug of the environment.
The type of the environment (PRODUCTION, STAGING, DEVELOPMENT, or PREVIEW).
The ID of the organization.
The slug of the organization.
The name of the organization.
The reference of the project.
Optional information about the batch, if applicable.
Optional information about the machine preset used for execution. The name of the machine preset.
The CPU allocation for the machine.
The memory allocation for the machine.
The cost in cents per millisecond for this machine preset.