Skip to content

Commit f18df88

Browse files
committed
Improved diagrams and copy
1 parent c0c0eca commit f18df88

7 files changed

+40
-38
lines changed

docs/images/run-lifecycle.png

5.88 KB
Loading
4.6 KB
Loading

docs/images/run-with-delay.png

5.79 KB
Loading

docs/images/run-with-retries.png

6.19 KB
Loading
2.19 KB
Loading

docs/images/run-with-ttl.png

96 Bytes
Loading

docs/runs-and-attempts.mdx

+40-38
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
---
2-
title: "Runs & Attempts"
2+
title: "Runs & attempts"
33
description: "Understanding the lifecycle of task execution in Trigger.dev"
44
---
55

6-
In Trigger.dev, the concepts of Runs and Attempts are fundamental to understanding how tasks are executed and managed. This article explains these concepts in detail and provides insights into the various states a Run can go through during its lifecycle.
6+
In Trigger.dev, the concepts of runs and attempts are fundamental to understanding how tasks are executed and managed. This article explains these concepts in detail and provides insights into the various states a run can go through during its lifecycle.
77

8-
## What are Runs?
8+
## What are runs?
99

10-
A Run is created when you trigger a task (e.g calling `yourTask.trigger({ foo: "bar" })`). It represents a single instance of a task being executed and contains the following key information:
10+
A run is created when you trigger a task (e.g calling `yourTask.trigger({ foo: "bar" })`). It represents a single instance of a task being executed and contains the following key information:
1111

1212
- A unique run ID
1313
- The current status of the run
1414
- The payload (input data) for the task
1515
- Lots of other metadata
1616

17-
## The Run Lifecycle
17+
## The run lifecycle
1818

19-
A Run can go through **various** states during its lifecycle. The following diagrams illustrate the possible state transitions:
19+
A run can go through **various** states during its lifecycle. The following diagram illustrates a typical state transition where a single run is triggered and completes successfully:
2020

2121
![Run Lifecycle](/images/run-lifecycle.png)
2222

23+
Runs can also find themselves in lots of other states depending on what's happening at any given time. The following sections describe all the possible states in more detail.
24+
2325
### Initial States
2426

25-
<Icon icon="rectangle-history" iconType="solid" color="#FBBF24" size={17} /> **Waiting for deploy**: If a task is triggered before it has been deployed, the Run enters this state and waits for the task to be deployed.
27+
<Icon icon="rectangle-history" iconType="solid" color="#FBBF24" size={17} /> **Waiting for deploy**: If a task is triggered before it has been deployed, the run enters this state and waits for the task to be deployed.
2628

27-
<Icon icon="clock" iconType="solid" color="#878C99" size={17} /> **Delayed**: When a Run is triggered with a delay, it enters this state until the specified delay period has passed.
29+
<Icon icon="clock" iconType="solid" color="#878C99" size={17} /> **Delayed**: When a run is triggered with a delay, it enters this state until the specified delay period has passed.
2830

29-
<Icon icon="rectangle-history" iconType="solid" color="#878C99" size={17} /> **Queued**: The Run is ready to be executed and is waiting in the queue.
31+
<Icon icon="rectangle-history" iconType="solid" color="#878C99" size={17} /> **Queued**: The run is ready to be executed and is waiting in the queue.
3032

3133
### Execution States
3234

@@ -40,7 +42,7 @@ A Run can go through **various** states during its lifecycle. The following diag
4042

4143
<Icon icon="circle-check" iconType="solid" color="#28BF5C" size={17} /> **Completed**: The task has successfully finished execution.
4244

43-
<Icon icon="ban" iconType="solid" color="#878C99" size={17} /> **Canceled**: The Run was manually canceled by the user.
45+
<Icon icon="ban" iconType="solid" color="#878C99" size={17} /> **Canceled**: The run was manually canceled by the user.
4446

4547
<Icon icon="circle-xmark" iconType="solid" color="#E11D48" size={17} /> **Failed**: The task has failed to complete successfully.
4648

@@ -52,30 +54,30 @@ A Run can go through **various** states during its lifecycle. The following diag
5254

5355
<Icon icon="bug" iconType="solid" color="#E11D48" size={17} /> **System failure**: An unrecoverable system error has occurred.
5456

55-
<Icon icon="trash-can" iconType="solid" color="#878C99" size={17} /> **Expired**: The Run's Time-to-Live (TTL) has passed before it could start executing.
57+
<Icon icon="trash-can" iconType="solid" color="#878C99" size={17} /> **Expired**: The run's Time-to-Live (TTL) has passed before it could start executing.
5658

5759
## Attempts
5860

59-
An Attempt represents a single execution of a task within a Run. A Run can have one or more Attempts, depending on the task's retry settings and whether it fails. Each Attempt has:
61+
An attempt represents a single execution of a task within a run. A run can have one or more attempts, depending on the task's retry settings and whether it fails. Each attempt has:
6062

6163
- A unique attempt ID
6264
- A status
6365
- An output (if successful) or an error (if failed)
6466

65-
When a task fails, it will be retried according to its retry settings, creating new Attempts until it either succeeds or reaches the retry limit.
67+
When a task fails, it will be retried according to its retry settings, creating new attempts until it either succeeds or reaches the retry limit.
6668

6769
![Run with retries](/images/run-with-retries.png)
6870

69-
## Run Completion
71+
## Run completion
7072

71-
A Run is considered finished when:
73+
A run is considered finished when:
7274

73-
1. The last Attempt succeeds, or
74-
2. The task has reached its retry limit and all Attempts have failed
75+
1. The last attempt succeeds, or
76+
2. The task has reached its retry limit and all attempts have failed
7577

76-
At this point, the Run will have either an output (if successful) or an error (if failed).
78+
At this point, the run will have either an output (if successful) or an error (if failed).
7779

78-
## Advanced Run Features
80+
## Advanced run features
7981

8082
### Idempotency Keys
8183

@@ -85,42 +87,42 @@ When triggering a task, you can provide an idempotency key to ensure the task is
8587
yourTask.trigger({ foo: "bar" }, { idempotencyKey: "unique-key" });
8688
```
8789

88-
- If a Run with the same idempotency key is already in progress, the new trigger will be ignored.
89-
- If the Run has already finished, the previous output or error will be returned.
90+
- If a run with the same idempotency key is already in progress, the new trigger will be ignored.
91+
- If the run has already finished, the previous output or error will be returned.
9092

91-
### Canceling Runs
93+
### Canceling runs
9294

93-
You can cancel an in-progress Run using the API or the dashboard:
95+
You can cancel an in-progress run using the API or the dashboard:
9496

9597
```ts
9698
runs.cancel(runId);
9799
```
98100

99-
When a Run is canceled:
101+
When a run is canceled:
100102

101103
– The task execution is stopped
102104

103-
– The Run is marked as canceled
105+
– The run is marked as canceled
104106

105107
– The task will not be retried
106108

107-
– Any in-progress child Runs are also canceled
109+
– Any in-progress child runs are also canceled
108110

109111
### Time-to-live (TTL)
110112

111-
You can set a TTL when triggering a Run:
113+
You can set a TTL when triggering a run:
112114

113115
```ts
114116
yourTask.trigger({ foo: "bar" }, { ttl: "10m" });
115117
```
116118

117-
If the Run hasn't started within the specified TTL, it will automatically expire. This is useful for time-sensitive tasks. Note that dev runs automatically have a 10-minute TTL.
119+
If the run hasn't started within the specified TTL, it will automatically expire. This is useful for time-sensitive tasks. Note that dev runs automatically have a 10-minute TTL.
118120

119121
![Run with TTL](/images/run-with-ttl.png)
120122

121-
### Delayed Runs
123+
### Delayed runs
122124

123-
You can schedule a Run to start after a specified delay:
125+
You can schedule a run to start after a specified delay:
124126

125127
```ts
126128
yourTask.trigger({ foo: "bar" }, { delay: "1h" });
@@ -130,19 +132,19 @@ This is useful for tasks that need to be executed at a specific time in the futu
130132

131133
![Run with delay](/images/run-with-delay.png)
132134

133-
### Replaying Runs
135+
### Replaying runs
134136

135-
You can create a new Run with the same payload as a previous Run:
137+
You can create a new run with the same payload as a previous run:
136138

137139
```ts
138140
runs.replay(runId);
139141
```
140142

141-
This is useful for re-running a task with the same input, especially for debugging or recovering from failures. The new Run will use the latest version of the task.
143+
This is useful for re-running a task with the same input, especially for debugging or recovering from failures. The new run will use the latest version of the task.
142144

143145
You can also replay runs from the dashboard using the same or different payload. Learn how to do this [here](/replaying).
144146

145-
### Waiting for Runs
147+
### Waiting for runs
146148

147149
#### triggerAndWait()
148150

@@ -158,7 +160,7 @@ Similar to `triggerAndWait()`, the `batchTriggerAndWait()` function lets you bat
158160

159161
### Runs API
160162

161-
The Runs API provides methods to interact with and manage Runs:
163+
The runs API provides methods to interact with and manage runs:
162164

163165
```ts
164166
// List all runs
@@ -177,9 +179,9 @@ runs.reschedule(runId, delay);
177179
runs.cancel(runId);
178180
```
179181

180-
These methods allow you to access detailed information about Runs and their Attempts, including payloads, outputs, parent Runs, and child Runs.
182+
These methods allow you to access detailed information about runs and their attempts, including payloads, outputs, parent runs, and child runs.
181183

182-
### Triggering Runs for Undeployed Tasks
184+
### Triggering runs for undeployed tasks
183185

184-
It's possible to trigger a Run for a task that hasn't been deployed yet. The Run will enter the "Waiting for deploy" state until the task is deployed. Once deployed, the Run will be queued and executed normally.
186+
It's possible to trigger a run for a task that hasn't been deployed yet. The run will enter the "Waiting for deploy" state until the task is deployed. Once deployed, the run will be queued and executed normally.
185187
This feature is particularly useful in CI/CD pipelines where you want to trigger tasks before the deployment is complete.

0 commit comments

Comments
 (0)