Skip to content

Commit 5dfa932

Browse files
committed
Tweaked the idempotency test task for more situations
1 parent 7ec2726 commit 5dfa932

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

references/hello-world/src/trigger/idempotency.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,17 @@ export const idempotency = task({
114114
export const idempotencyBatch = task({
115115
id: "idempotency-batch",
116116
maxDuration: 60,
117-
run: async (payload: any) => {
117+
run: async ({ additionalItems }: { additionalItems?: 2 }) => {
118118
const successfulKey = await idempotencyKeys.create("a", { scope: "global" });
119119
const failureKey = await idempotencyKeys.create("b", { scope: "global" });
120120
const anotherKey = await idempotencyKeys.create("c", { scope: "global" });
121121
const batchKey = await idempotencyKeys.create("batch", { scope: "global" });
122122

123+
const moreItems = Array.from({ length: additionalItems ?? 0 }, (_, i) => ({
124+
payload: { message: `Hello, world ${i}!` },
125+
options: { idempotencyKey: `key-${i}`, idempotencyKeyTTL: "120s" },
126+
}));
127+
123128
const batch1 = await childTask.batchTriggerAndWait(
124129
[
125130
{
@@ -133,6 +138,7 @@ export const idempotencyBatch = task({
133138
{
134139
payload: { message: "Hello, world 3", duration: 500, failureChance: 0 },
135140
},
141+
...moreItems,
136142
],
137143
{
138144
idempotencyKey: batchKey,
@@ -157,6 +163,7 @@ export const idempotencyBatch = task({
157163
{
158164
payload: { message: "Hello, world 3", duration: 500, failureChance: 0 },
159165
},
166+
...moreItems,
160167
],
161168
{
162169
idempotencyKey: batchKey,

0 commit comments

Comments
 (0)