Skip to content

Commit

Permalink
fix: Fixes issue where last error was overwritten on dead queue insert
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
jakobo committed Jan 17, 2024
1 parent 6bcef68 commit 5ab3e68
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,20 @@ export class Worker<
const err = new MaxAttemptsExceededError(
`Exceeded the maximum number of retries (${this.doc.attempts.max}) for this job`
);
err.original = this.doc.error ? new Error(this.doc.error) : undefined;
const event = {
queue: this.fqqn(),
ref: this.doc.ref,
payload: this.options.payload,
attempt: this.doc.attempts.tries,
maxTries: this.doc.attempts.max,
error: typeof err === "string" ? new Error(err) : err,
error: this.doc.error,
next: this.driver.findNext(this.doc),
};
await this.driver.transaction(async (tx) => {
await this.driver.createNext(this.doc); // failing next prevents dead-ing the job
await this.driver.dead(this.doc, tx);
this.emitter.emit("dead", event, context);
this.emitter.emit("dead", { ...event, error: err }, context);
});
} catch (e) {
const err = new WorkerProcessingError(
Expand Down

0 comments on commit 5ab3e68

Please # to comment.