Skip to content

Commit 7b6e72d

Browse files
authored
Merge pull request #57 from SimonErm/fix/missing-prop-on-trigger-failure
Fix/missing prop on trigger failure
2 parents c817e6e + 13d679a commit 7b6e72d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ export class Queue {
327327

328328
this.jobStore.removeJob(rawJob);
329329
} catch (error) {
330-
worker.triggerFailure(job, error);
331330
const { attempts } = rawJob;
332331
// tslint:disable-next-line: prefer-const
333332
let { errors, failedAttempts } = JSON.parse(rawJob.metaData);
@@ -337,6 +336,7 @@ export class Queue {
337336
failed = new Date().toISOString();
338337
}
339338
const metaData = JSON.stringify({ errors: [...errors, error], failedAttempts });
339+
worker.triggerFailure({ ...job, metaData, failed }, error);
340340
this.jobStore.updateJob({ ...rawJob, ...{ active: FALSE, metaData, failed } });
341341
} finally {
342342
delete this.runningJobPromises[job.id]

src/__tests__/Queue.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,23 @@ describe('Queue Basics', () => {
145145
})
146146
);
147147
queue.configure({ onQueueFinish: onQueueFinish });
148-
queue.addWorker(
149-
new Worker<Payload>('testWorker', executer, { concurrency: 1, onFailure: onError })
150-
);
148+
queue.addWorker(new Worker<Payload>('testWorker', executer, { concurrency: 1, onFailure: onError }));
149+
queue.addJob('testWorker', { test: '1' }, { attempts: 0, timeout: 5, priority: 0 }, false);
150+
queue.start();
151+
});
152+
it('trigger onFailure', (done) => {
153+
const executer = async () => {
154+
throw new Error('This is an error');
155+
};
156+
const onFailure = (job: Job<Payload>, _: Error) => {
157+
try {
158+
expect(job.failed).not.toEqual('');
159+
done();
160+
} catch (error) {
161+
done(error);
162+
}
163+
};
164+
queue.addWorker(new Worker<Payload>('testWorker', executer, { concurrency: 1, onFailure }));
151165
queue.addJob('testWorker', { test: '1' }, { attempts: 0, timeout: 5, priority: 0 }, false);
152166
queue.start();
153167
});

0 commit comments

Comments
 (0)