diff --git a/docs/context.mdx b/docs/context.mdx new file mode 100644 index 0000000000..618e80a74d --- /dev/null +++ b/docs/context.mdx @@ -0,0 +1,192 @@ +--- +title: "Context" +description: "Get the context of a task run." +--- + +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. + + +Here's an example: + +```typescript +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 ID of the task. + + + The file path of the task. + + + + + + + + The ID of the execution attempt. + + + The attempt number. + + + 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 ID of the task run. + + + The context of the task run. + + + An array of [tags](/tags) associated with the task run. + + + Whether this is a [test run](/run-tests). + + + The creation time of the task run. + + + The start time of the task run. + + + An optional [idempotency key](/idempotency) for the task run. + + + The [maximum number of attempts](/triggering#maxattempts) 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](/run-usage). + + + The cost of the task run in cents when the `run()` function is called. For live values use the [usage SDK functions](/run-usage). + + + The base cost of the task run in cents when the `run()` function is called. For live values use the [usage SDK functions](/run-usage). + + + The [version](/versioning) of the task run. + + + The [maximum allowed duration](/runs/max-duration) for the task run. + + + + + + + + The ID of the queue. + + + The name of the queue. + + + + + + + + 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 ID of the project. + + + The reference of the project. + + + The slug of the project. + + + The name of the project. + + + + + + Optional information about the batch, if applicable. + + + The ID of the batch. + + + + + + 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. + + + diff --git a/docs/mint.json b/docs/mint.json index 41f936223c..c934c6f9d1 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -163,7 +163,8 @@ "runs/max-duration", "tags", "runs/metadata", - "run-usage" + "run-usage", + "context" ] }, {