Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

success events emitted for failed job #48

Open
ghost opened this issue Oct 23, 2023 · 2 comments
Open

success events emitted for failed job #48

ghost opened this issue Oct 23, 2023 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 23, 2023

documentation states that success and success:job name events will be emitted only when a job succeeds, but if the job is failed manually by calling job.fail(err).save(); the messages will be emitted anyway.

const agenda = new Agenda();

const handler = (job) => job.fail('error').save();
agenda.define('test', handler);

agenda.on('success', () => console.log('success'));

await agenda.start();
await agenda.now('test');

// will print 'success' even if the job has failed

link to code

@riddlewiggler
Copy link

Shouldn't you first disable the job @volpd?

It looks like fail will only set some values of the specified job, it won't stop job execution. Correct me if I'm wrong.

@ghost
Copy link
Author

ghost commented Oct 27, 2023

@riddlewiggler yes, i forgot that part on the example, still the problem is not that the job is executed.

what happens is:

  • job is executed
  • job is manually failed (and disabled) in the handler
  • handler returns
  • agenda emits success message, even if the job has failed

yes, i saw that fail() will only set the fail reason and update the failCount on the job, but I would have expected Agenda to check the status of the job before emitting success or fail, whereas it seems fail will be emitted if the handler throws an exception, and success will be emitted when the handler returns, regardless of the status of the job.

I don't think this was mentioned in the documentation, if it is the desired behavior I think it should be clarified, since it was clear to me only after inspecting the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant