-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Pause or cancel a batch? #919
Comments
Great feature request. Something like that doesn't currently exist. Currently, it's possible to manually Discard each of the jobs within a batch, but that would still result in the Batch Callback(s) being triggered. There aren't any manual Batch operations right now that are analogous to a Job being able to be manually retried/rescheduled/discarded. Thinking aloud here on designing something new:
|
If you simply want a workaround, you could discard all of the jobs this way: # Uses private APIs, so no promises this will continue working
batch._record.jobs.where(performed_at: nil).each do |good_job|
good_job.discard_job("Manually discarded within batch")
end |
...and now that I'm looking through the manual job actions |
Wow, thanks for the extremely quick and thorough response!
Definitely seems like a different concept. For our use case, at least, the idea that a batch gets "discarded" just because one of it's jobs is discarded isn't super meaningful. If we queue up 10,000 invoices to be sent and 20 of them fail for some reason, the batch itself was still a success. That's fundamentally different than a user explicitly cancelling the batch.
I'm fine with workarounds but this seems quite heavyweight for a large number of jobs. Seems like this would work fine as well? batch._record.jobs.where(performed_at: nil).update_all {finished_at: Time.now, error: 'cancelled'}
Batch callbacks don't seem necessary to me for this use case, but I agree that others might want it. I'll move forward with this approach for now. If you're actually interested in implementing this as a first class feature, it seems like being able to toggle some sort of state on the batch (active | paused | cancelled) without needing to update the job records themselves would be ideal when dealing with large batches. Thanks again! |
That sounds right to me. I think "Batch -> Discarded" is pretty ambiguous currently because it really means "a job within the batch was discarded, triggering the discarded batch callback". I'm trying to use as few words as possible here to denote states :-) But maybe "Cancel" is the right word. I'll have to think about that some more. (same problem as #890).
Yep, that code snippet will work. The one difference is that the
I agree that would be ideal, it's also something I'm trying to avoid: adding transitive job states (same problem as #749). Sorry, that was a lot of thinking while typing! Your feedback is exactly what I want. I think this is a pretty important User Action to support. |
I'm using the new batches functionality and it's working well. However, I haven't been able to find a way to pause or cancel the execution of a particular batch. I tried setting the
finished_at
value but that didn't have any effect.I could do a bulk update on all jobs in the batch, but even then it's not clear what I should be setting. Any guidance would be appreciated.
Thanks!
The text was updated successfully, but these errors were encountered: