Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ export class Queue {

this.jobStore.removeJob(rawJob);
} catch (error) {
worker.triggerFailure(job, error);
const { attempts } = rawJob;
// tslint:disable-next-line: prefer-const
let { errors, failedAttempts } = JSON.parse(rawJob.metaData);
Expand All @@ -337,6 +336,7 @@ export class Queue {
failed = new Date().toISOString();
}
const metaData = JSON.stringify({ errors: [...errors, error], failedAttempts });
worker.triggerFailure({ ...job, metaData, failed }, error);
this.jobStore.updateJob({ ...rawJob, ...{ active: FALSE, metaData, failed } });
} finally {
delete this.runningJobPromises[job.id]
Expand Down
20 changes: 17 additions & 3 deletions src/__tests__/Queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,23 @@ describe('Queue Basics', () => {
})
);
queue.configure({ onQueueFinish: onQueueFinish });
queue.addWorker(
new Worker<Payload>('testWorker', executer, { concurrency: 1, onFailure: onError })
);
queue.addWorker(new Worker<Payload>('testWorker', executer, { concurrency: 1, onFailure: onError }));
queue.addJob('testWorker', { test: '1' }, { attempts: 0, timeout: 5, priority: 0 }, false);
queue.start();
});
it('trigger onFailure', (done) => {
const executer = async () => {
throw new Error('This is an error');
};
const onFailure = (job: Job<Payload>, _: Error) => {
try {
expect(job.failed).not.toEqual('');
done();
} catch (error) {
done(error);
}
};
queue.addWorker(new Worker<Payload>('testWorker', executer, { concurrency: 1, onFailure }));
queue.addJob('testWorker', { test: '1' }, { attempts: 0, timeout: 5, priority: 0 }, false);
queue.start();
});
Expand Down