Getting Started
Fundamentals
- Tasks
- Triggering
- Runs
- API keys
- Configuration
Development
Deployment
- Environment Variables
- CLI deploy command
- GitHub Actions
- Deployment integrations
Writing tasks
Frontend usage
Realtime API
API reference
- Overview & Authentication
- Tasks API
- Runs API
- Schedules API
- Env Vars API
- Projects API
CLI
- Introduction
- Commands
Context
Get the context of a task run.
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 (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 ID of the task run.
The context of the task run.
The creation time of the task run.
The start time of the task run.
An optional idempotency key for the task run.
The maximum number of attempts allowed for this 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 maximum allowed duration for the task run.
Was this page helpful?
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;
}
},
});