bull icon indicating copy to clipboard operation
bull copied to clipboard

Event "failed" is fired for every attempt [BUG]

Open misos1 opened this issue 6 years ago • 7 comments

Description

It should be fired like "global:failed" only once after is job definitely failed.

Minimal, Working Test code to reproduce the issue.

let Queue = require("bull");
let queue = new Queue("queue", { defaultJobOptions: { attempts: 3 } });
queue.process(_job => { throw(new Error("err")); });
queue.on("failed", job => console.log("failed", job.id, job.attemptsMade, job.opts.attempts));
queue.on("global:failed", job_id => console.log("global:failed", job_id));
queue.add({});

Possible output:

failed 358 1 3
failed 358 2 3
global:failed 358
failed 358 3 3

Bull version

3.10.0

Additional information

misos1 avatar Jul 17 '19 20:07 misos1

I can take this as a feature request, but not as a bug since it works like this as designed.

manast avatar Jul 18 '19 18:07 manast

Ok, but who would expect such difference between local and global version of event?

misos1 avatar Jul 18 '19 18:07 misos1

aha, global only is emitted once but local for every retry. Then I agree, it is a bug.

manast avatar Jul 18 '19 19:07 manast

Maybe it is not so bad to have some separate event fired on failed attempt "failed_attempt". But I suppose "failed" everywhere else means "definitely failed". Or at least I hope that functions like getFailed, getFailedCount, getState are working with "definitely failed" concept like "global:failed" event. There is nothing about that in reference.

misos1 avatar Jul 18 '19 19:07 misos1

so I think the current failed event should mean definitive fail, and we could have a new event "retry" to signal every retry.

manast avatar Jul 20 '19 08:07 manast

New failed_attempt event would be really useful.

Note, for those who struggle with making a difference between failed job and failed_attempts there is job attribute finishedOn Unix Timestamp, which is set when job is "definitely and finally failed".

animir avatar Jul 13 '20 02:07 animir

The retry event has not yet been implemented, or did I overlook it?

One can also compare job param attemptsMade to the JobOptions.attempts setting within the failed callback.

mirupal avatar Sep 02 '22 08:09 mirupal