Skip to content

Add capability to discard duplicate jobs with concurrency configuration #523

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

joelzwarrington
Copy link

@joelzwarrington joelzwarrington commented Feb 25, 2025

Closes #176

Add ability to discard duplicate jobs instead of becoming blocked. When configuring concurrency_limits with at_limit: discard jobs scheduled above the concurrency limit are discarded and not executed.

Implementation Details

  • adds class_attribute concurrency_at_limit and at_limit option to concurrency_limits
  • adds methods to Semaphore to detect when a job would be above the concurrency limit
  • adds logic to discard a job on dispatch when at concurrency limit

@joelzwarrington
Copy link
Author

Thanks for the review @rosa ❤️, I'll review your comments more thoroughly and make some changes. 😊

Copy link
Author

@joelzwarrington joelzwarrington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rosa, I've made a few changes and believe to have encountered weird interactions with bulk enqueuing which might be a bug. Let me know if you'd like those changes split out into another PR.

@rajeevriitm
Copy link

I am really in need of this feature. As its not yet available , could you help me in implementing this ? I have a ContinuousSearchJob thats run with recurring.yml . Sometimes the job takes longer and I dont want another job to be added to the queue unless the existing one is finished. Could you help me with the best way I can implement this currently?

@joelzwarrington
Copy link
Author

@rajeevriitm if you have a look at the read me you should find concurrency controls are available for you to use.

The only difference being that jobs will always be blocked, so you may get several jobs that are awaiting execution.

@joelzwarrington
Copy link
Author

@rosa any updates on your review here?

@rynonl
Copy link

rynonl commented May 30, 2025

@rosa Just pinging this. Would love to see this functionality get merged!

@danlo
Copy link
Contributor

danlo commented Jun 11, 2025

@rosa +1

@rosa
Copy link
Member

rosa commented Jun 11, 2025

Hey, sorry everyone! I've been crazy busy at work in a bunch of unrelated things, but I'm planning for at least a day of Solid Queue work to catch up with all issues and PRs very soon. Thanks y'all for your patience and sorry for the delay!

@joelzwarrington
Copy link
Author

Thanks for the review. Gonna have a look and implement any feedback this week

@joelzwarrington
Copy link
Author

It'd be a good idea to update https://github.com/rails/rails/blob/c049370882474acffbc8fd5be458e6ecd1d7d1cb/guides/source/active_job_basics.md?plain=1#L346 when merging this as I've changed SolidQueue::Job::EnqueueError to inherit from ActiveJob::EnqueueError.

@joelzwarrington
Copy link
Author

@rosa, pull request is ready for you review again! Let me know what you think.

If you're on-board with these changes, I'll also add a PR to update the RoR edge guide.

Co-authored-by: Philippe Tring <[email protected]>
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

Successfully merging this pull request may close these issues.

Discard duplicate jobs
6 participants