|
1 |
| -import { logger, task, wait } from "@trigger.dev/sdk/v3"; |
| 1 | +import { logger, queue, task, wait } from "@trigger.dev/sdk/v3"; |
2 | 2 |
|
3 | 3 | type Payload = {
|
4 | 4 | count?: number;
|
@@ -70,6 +70,7 @@ export const nestedDependencies = task({
|
70 | 70 | maxDepth,
|
71 | 71 | waitSeconds,
|
72 | 72 | failAttemptChance,
|
| 73 | + batchSize, |
73 | 74 | });
|
74 | 75 | logger.log(`Triggered complete ${i + 1}/${batchSize}`);
|
75 | 76 |
|
@@ -153,3 +154,36 @@ export const bulkPermanentlyFrozen = task({
|
153 | 154 | );
|
154 | 155 | },
|
155 | 156 | });
|
| 157 | + |
| 158 | +const oneAtATime = queue({ |
| 159 | + name: "race-condition", |
| 160 | + concurrencyLimit: 1, |
| 161 | +}); |
| 162 | + |
| 163 | +export const raceConditionCheckpointDequeue = task({ |
| 164 | + id: "race-condition-checkpoint-dequeue", |
| 165 | + queue: oneAtATime, |
| 166 | + run: async ({ isBatch = true }: { isBatch?: boolean }) => { |
| 167 | + await holdConcurrency.trigger({ waitSeconds: 45 }); |
| 168 | + |
| 169 | + if (isBatch) { |
| 170 | + await fixedLengthTask.batchTriggerAndWait( |
| 171 | + Array.from({ length: 1 }, (_, i) => ({ |
| 172 | + payload: { waitSeconds: 5 }, |
| 173 | + })) |
| 174 | + ); |
| 175 | + } else { |
| 176 | + await fixedLengthTask.triggerAndWait({ waitSeconds: 5 }); |
| 177 | + } |
| 178 | + |
| 179 | + logger.log(`Successfully completed task`); |
| 180 | + }, |
| 181 | +}); |
| 182 | + |
| 183 | +export const holdConcurrency = task({ |
| 184 | + id: "hold-concurrency", |
| 185 | + queue: oneAtATime, |
| 186 | + run: async ({ waitSeconds = 60 }: { waitSeconds?: number }) => { |
| 187 | + await new Promise((resolve) => setTimeout(resolve, waitSeconds * 1000)); |
| 188 | + }, |
| 189 | +}); |
0 commit comments