Skip to content

Commit ff5eac0

Browse files
authored
Fix duplicate jobs in product creation (#1376)
* Add jobId to prevent duplicate jobs * Create snapshot after start
1 parent 0b84e1a commit ff5eac0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/lib/server/workflow/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class Workflow {
8181

8282
await flow.createSnapshot(flow.flow.getSnapshot().context);
8383
flow.flow.start();
84+
await flow.createSnapshot(flow.flow.getSnapshot().context);
8485
await DatabaseWrites.productTransitions.create({
8586
data: {
8687
ProductId: productId,

src/lib/server/workflow/state-machine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ export const WorkflowStateMachine = setup({
305305
type: BullMQ.JobType.Product_Create,
306306
productId: context.productId
307307
},
308-
BullMQ.Retry0f600
308+
{
309+
...BullMQ.Retry0f600,
310+
// prevent duplicate jobs
311+
jobId: `${BullMQ.JobType.Product_Create}_${context.productId}`
312+
}
309313
);
310314
}
311315
],

0 commit comments

Comments
 (0)