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

Removing completed jobs automatically & atomically #354

Closed
bradvogel opened this issue Oct 10, 2016 · 3 comments
Closed

Removing completed jobs automatically & atomically #354

bradvogel opened this issue Oct 10, 2016 · 3 comments

Comments

@bradvogel
Copy link
Contributor

It's our desire to remove jobs automatically upon completion. My understanding of the Bull API is that we should do this by listening to the completed event on the queue and call job.remove(), like this:

this.on('completed', job => job.remove());

However, we're finding that some completed jobs aren't getting removed. The likely reason for this is that the server is occasionally being killed right after the job is moved to "completed", but before job.remove() can be called. Since events are broadcast locally, there is no second server to pick up the message, the job stays around forever. Our current workaround is to run a cron job every hour that calls clean(10 * 1000, 'completed') on the queue.

I wanted to get your thoughts on the following possible approaches to clean up completed jobs:

  1. Add a removeOnCompleted option to the job and have the moveToCompleted script atomically remove the job upon completion.
  2. Use the new distributed events architecture to broadcast the 'completed' event to all workers, so one can remove the job.
@manast
Copy link
Member

manast commented Oct 10, 2016

do you have any chance to test with master to see if it works better with the distributed events?
An atomic remove may be an interesting feature and not difficult to implement either.

@bradvogel
Copy link
Contributor Author

Not yet. Will test though. I think we should internalize removal through a new removeOnComplete job option, pending the outcome of bug #356 which might affect this.

@bradvogel bradvogel changed the title Removing completed jobs automatically Removing completed jobs automatically & atomically Oct 14, 2016
bradvogel added a commit to mixmaxhq/bull that referenced this issue Oct 15, 2016
@bradvogel
Copy link
Contributor Author

Fixed in https://github.com/OptimalBits/bull/pull/361/files

duyenddd added a commit to duyenddd/bull that referenced this issue Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants