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
Prevent duplicate job processing by using idempotency keys. When a job with the same `idempotencyKey` is added while an existing job with that key is still `waiting`, `delayed`, or `reserved`, the existing job ID is returned instead of creating a duplicate.
218
+
219
+
```typescript
220
+
// First attempt - creates new job
221
+
const id1 =awaitqueue.addJob('send-email', {
222
+
payload: { to: 'user@example.com', subject: 'Welcome', body: 'Hello!' },
223
+
idempotencyKey: 'welcome-email-user123'
224
+
});
225
+
226
+
// Second attempt with same key - returns existing job ID
227
+
const id2 =awaitqueue.addJob('send-email', {
228
+
payload: { to: 'user@example.com', subject: 'Welcome', body: 'Hello!' },
229
+
idempotencyKey: 'welcome-email-user123'
230
+
});
231
+
232
+
console.log(id1===id2); // true - no duplicate job created
233
+
```
234
+
235
+
**Idempotency Key Lifecycle:**
236
+
- Keys are automatically cleaned up when jobs complete (successfully or with failure)
237
+
- After completion/failure, the same key can be reused for new jobs
238
+
- Deduplication lasts as long as the job remains in the queue
0 commit comments