Fundamentals
Writing tasks
Configuration
- trigger.config.ts
- Build extensions
Development
Deployment
- Overview
- Environment Variables
- GitHub Actions
- Preview branchesv4
- Atomic deploys
- Deployment integrations
Frontend usage
- Overview & Auth
- React hooks
CLI
- Introduction
- Commands
Using the Dashboard
Troubleshooting
Self-hosting
v4- Overview
- Docker compose
- Environment variables
Self-hosting
Open source
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.
The ID of the environment.
The slug of the environment.
The type of the environment (PRODUCTION, STAGING, DEVELOPMENT, or PREVIEW).
If the environment is PREVIEW
then this will be the branch name.
The name of the commit author.
The message of the commit.
The ref of the commit.
The SHA of the commit.
Whether the commit is dirty, i.e. there are uncommitted changes.
The remote URL of the repository.
The number of the pull request.
The title of the pull request.
The state of the pull request (open, closed, or merged).
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;
}
},
});