-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement job batches #32
Conversation
@inkstak Sorry for not asking first, but I took a stab at implementing batches for |
Thanks, I’m really interested, but I won’t be available this week. I come back to you next week. |
@inkstak Any updates on this? I added some docs on callbacks as well. |
As I said, I'm really interested : Since few months, I'm considering replacing Sidekiq Batches by AcidicJob, moving back to ActiveJob, and why not replacing Sidekiq by SolidQueue. I haven't thought about using ActiveJob::Status to monitor batches so your idea make me thinking a lot. Few things to improve: 1 - I'd prefer to pass an array of jobs as an argument if we had to pass dozens of jobs: ActiveJob::Status::Batch.new(array_of_jobs) 2 - We could benefit from This can be achieved by implementing the method module ActiveJob
module Status
class Batch
def initialize(jobs)
@jobs = jobs
@storage = ActiveJob::Status::Storage.new
end
def statuses
read.pluck(:status)
end
# ....
private
def read
@storage.read_multi(@jobs)
end We could then implement other methods to get an average progress of the batch, the raised exceptions, etc.. |
I really like
Done!
Done! I've had to change the logic for calculating the statuses slightly. cache_keys = ['job_1', 'job_2', 'job_3']
cache.read_multi(*cache_keys)
# { 'job_1' => { status: 'finished' }, 'job_2' => { status: 'failed' }, 'job_3' => { status: 'finished' } } However, if there's a cache miss, here's what happens cache_keys = ['job_1', 'job_2', 'job_3']
cache.read_multi(*cache_keys)
# { 'job_1' => { status: 'finished' }, 'job_3' => { status: 'finished' } } It might appear that all jobs finished successfully, but in reality, we missed the status for @inkstak Can you take another look? |
The |
👍 I'll fix this and release a new version soon. |
FYI, I have a PR open to add batch support to SolidQueue: rails/solid_queue#142 It hasn't gotten any response yet, so I'm not sure how it'll turn out in the end. I opened it with a partial but functional implementation to get the conversation started and hopefully land batch support in the next few months. |
Merged in v1.0.1...v1.1.0.beta.0. |
@inkstak Just wanted to circle back and thank you for the help again. We've been using this in production for a while now and it's working without a hitch! |
Summary
Implements job batches. This is used to group multiple job and "calculate" a single status for the group of jobs.
This is useful when you want to schedule multiple batches of work for a single resource in parallel, but you want to know when all of them complete or if one fails.
It's a really simple implementation that doesn't add any additional complexity, just adds a way to calculate a single status for a group of statuses.
Background
We're looking to switch from Sidekiq to SolidQueue, but we use Sidekiq batches. This gem provides a lot of the underlying mechanics, but not the actual batches. We'd love to be able to complement SolidQueue with this gem to achieve equivalent functionality we had in Sidekiq.