Skip to content

Commit b6c9112

Browse files
authored
Merge pull request #3 from sliss/fix-duplicate-key-on-timeout-retry
fix: E11000 duplicate key error when creating timeout retry task
2 parents eb0a4d8 + 862b40c commit b6c9112

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/taskSchema.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,19 @@ taskSchema.statics.expireTimedOutTasks = async function expireTimedOutTasks() {
175175
}
176176

177177
if (task.retryOnTimeoutCount > 0) {
178+
// Copy task data but remove _id so MongoDB generates a new one
179+
const taskData = task.toObject({ virtuals: false });
180+
delete taskData._id;
178181
await Task.create({
179-
...task.toObject({ virtuals: false }),
182+
...taskData,
180183
status: 'pending',
184+
retryOnTimeoutCount: task.retryOnTimeoutCount - 1,
185+
startedRunningAt: null,
186+
finishedRunningAt: null,
187+
workerName: null,
188+
error: null,
189+
result: null,
190+
timeoutAt: null,
181191
schedulingTimeoutAt: now.valueOf() + 10 * 60 * 1000
182192
});
183193
} else {

0 commit comments

Comments
 (0)