You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/idempotency.mdx
+53-13Lines changed: 53 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,17 @@ description: "An API call or operation is “idempotent” if it has the same re
5
5
6
6
We currently support idempotency at the task level, meaning that if you trigger a task with the same `idempotencyKey` twice, the second request will not create a new task run.
7
7
8
+
<Warning>
9
+
In version 3.3.0 and later, the `idempotencyKey` option is not available when using
10
+
`triggerAndWait` or `batchTriggerAndWait`, due to a bug that would sometimes cause the parent task
11
+
to become stuck. We are working on a fix for this issue.
12
+
</Warning>
13
+
8
14
## `idempotencyKey` option
9
15
10
16
You can provide an `idempotencyKey` to ensure that a task is only triggered once with the same key. This is useful if you are triggering a task within another task that might be retried:
// Do something else, that may throw an error and cause the task to be retried
34
+
thrownewError("Something went wrong");
28
35
},
29
36
});
30
37
```
@@ -33,7 +40,7 @@ You can use the `idempotencyKeys.create` SDK function to create an idempotency k
33
40
34
41
We automatically inject the run ID when generating the idempotency key when running inside a task by default. You can turn it off by passing the `scope` option to `idempotencyKeys.create`:
// Do something else, that may throw an error and cause the task to be retried
119
+
thrownewError("Something went wrong");
120
+
},
121
+
});
122
+
```
123
+
124
+
You can use the following units for the `idempotencyKeyTTL` option:
125
+
126
+
-`s` for seconds (e.g. `60s`)
127
+
-`m` for minutes (e.g. `5m`)
128
+
-`h` for hours (e.g. `2h`)
129
+
-`d` for days (e.g. `3d`)
130
+
91
131
## Payload-based idempotency
92
132
93
133
We don't currently support payload-based idempotency, but you can implement it yourself by hashing the payload and using the hash as the idempotency key.
forawait (const run ofruns.subscribeToBatch("batch_1234")) {
15
+
console.log(run);
16
+
}
17
+
```
18
+
19
+
</RequestExample>
20
+
21
+
This function subscribes to all changes for runs in a batch. It returns an async iterator that yields the a run object whenever a run in the batch is updated. The iterator does not complete on it's own, you must manually `break` the loop when you want to stop listening for updates.
22
+
23
+
### Authentication
24
+
25
+
This function supports both server-side and client-side authentication. For server-side authentication, use your API key. For client-side authentication, you must generate a public access token with one of the following scopes:
26
+
27
+
-`read:batch:<batchId>`
28
+
-`read:runs` will provide access to all runs (not recommended for production use)
29
+
30
+
To generate a public access token, use the `auth.createPublicToken` function:
31
+
32
+
```ts
33
+
import { auth } from"@trigger.dev/sdk/v3";
34
+
35
+
// Somewhere in your backend code
36
+
const publicToken =awaitauth.createPublicToken({
37
+
scopes: {
38
+
read: {
39
+
batch: ["batch_1234"],
40
+
},
41
+
},
42
+
});
43
+
```
44
+
45
+
### Response
46
+
47
+
The AsyncIterator yields an object with the following properties:
0 commit comments