@@ -3,7 +3,13 @@ title: "Context"
3
3
description : " Get the context of a task run."
4
4
---
5
5
6
- Context (` ctx ` ) is a way to get information about a task. Here's an example:
6
+ Context (` ctx ` ) is a way to get information about a run.
7
+
8
+ <Note >
9
+ 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.
10
+ </Note >
11
+
12
+ Here's an example:
7
13
8
14
``` typescript
9
15
import { task } from " @trigger.dev/sdk/v3" ;
@@ -22,10 +28,9 @@ export const parentTask = task({
22
28
## Context properties
23
29
24
30
<ResponseField name = " task" type = " object" >
25
- Information about the task being executed.
26
- <Expandable title = " properties" >
31
+ <Expandable title = " properties" defaultOpen = { true } >
27
32
<ResponseField name = " exportName" type = " string" >
28
- The export name of the task.
33
+ The exported function name of the task e.g. ` myTask ` if you defined it like this: ` export const myTask = task(...) ` .
29
34
</ResponseField >
30
35
<ResponseField name = " id" type = " string" >
31
36
The ID of the task.
@@ -37,7 +42,6 @@ export const parentTask = task({
37
42
</ResponseField >
38
43
39
44
<ResponseField name = " attempt" type = " object" >
40
- Information about the current execution attempt.
41
45
<Expandable title = " properties" >
42
46
<ResponseField name = " id" type = " string" >
43
47
The ID of the execution attempt.
@@ -61,7 +65,6 @@ export const parentTask = task({
61
65
</ResponseField >
62
66
63
67
<ResponseField name = " run" type = " object" >
64
- Information about the task run.
65
68
<Expandable title = " properties" >
66
69
<ResponseField name = " id" type = " string" >
67
70
The ID of the task run.
@@ -70,10 +73,10 @@ export const parentTask = task({
70
73
The context of the task run.
71
74
</ResponseField >
72
75
<ResponseField name = " tags" type = " array" >
73
- An array of tags associated with the task run.
76
+ An array of [ tags] ( /tags ) associated with the task run.
74
77
</ResponseField >
75
78
<ResponseField name = " isTest" type = " boolean" >
76
- Whether this is a test run.
79
+ Whether this is a [ test run] ( /run-tests ) .
77
80
</ResponseField >
78
81
<ResponseField name = " createdAt" type = " date" >
79
82
The creation time of the task run.
@@ -82,31 +85,30 @@ export const parentTask = task({
82
85
The start time of the task run.
83
86
</ResponseField >
84
87
<ResponseField name = " idempotencyKey" type = " string" optional >
85
- An optional idempotency key for the task run.
88
+ An optional [ idempotency key] ( /idempotency ) for the task run.
86
89
</ResponseField >
87
90
<ResponseField name = " maxAttempts" type = " number" optional >
88
- The maximum number of attempts allowed for this task run.
91
+ The [ maximum number of attempts] ( /triggering#maxattempts ) allowed for this task run.
89
92
</ResponseField >
90
93
<ResponseField name = " durationMs" type = " number" >
91
- The duration of the task run in milliseconds.
94
+ The duration of the task run in milliseconds when the ` run() ` function is called. For live values use the [ usage SDK functions ] ( /run-usage ) .
92
95
</ResponseField >
93
96
<ResponseField name = " costInCents" type = " number" >
94
- The cost of the task run in cents.
97
+ The cost of the task run in cents when the ` run() ` function is called. For live values use the [ usage SDK functions ] ( /run-usage ) .
95
98
</ResponseField >
96
99
<ResponseField name = " baseCostInCents" type = " number" >
97
- The base cost of the task run in cents.
100
+ 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 ) .
98
101
</ResponseField >
99
102
<ResponseField name = " version" type = " string" optional >
100
- The version of the task run.
103
+ The [ version] ( /versioning ) of the task run.
101
104
</ResponseField >
102
105
<ResponseField name = " maxDuration" type = " number" optional >
103
- The maximum allowed duration for the task run.
106
+ The [ maximum allowed duration] ( /runs/max-duration ) for the task run.
104
107
</ResponseField >
105
108
</Expandable >
106
109
</ResponseField >
107
110
108
111
<ResponseField name = " queue" type = " object" >
109
- Information about the queue the task is running in.
110
112
<Expandable title = " properties" >
111
113
<ResponseField name = " id" type = " string" >
112
114
The ID of the queue.
@@ -118,7 +120,6 @@ export const parentTask = task({
118
120
</ResponseField >
119
121
120
122
<ResponseField name = " environment" type = " object" >
121
- Information about the execution environment.
122
123
<Expandable title = " properties" >
123
124
<ResponseField name = " id" type = " string" >
124
125
The ID of the environment.
@@ -133,7 +134,6 @@ export const parentTask = task({
133
134
</ResponseField >
134
135
135
136
<ResponseField name = " organization" type = " object" >
136
- Information about the organization.
137
137
<Expandable title = " properties" >
138
138
<ResponseField name = " id" type = " string" >
139
139
The ID of the organization.
@@ -148,7 +148,6 @@ export const parentTask = task({
148
148
</ResponseField >
149
149
150
150
<ResponseField name = " project" type = " object" >
151
- Information about the project.
152
151
<Expandable title = " properties" >
153
152
<ResponseField name = " id" type = " string" >
154
153
The ID of the project.
0 commit comments