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

Implement batch functionality #691

Closed
2 of 3 tasks
bensheldon opened this issue Aug 8, 2022 · 0 comments
Closed
2 of 3 tasks

Implement batch functionality #691

bensheldon opened this issue Aug 8, 2022 · 0 comments

Comments

@bensheldon
Copy link
Owner

bensheldon commented Aug 8, 2022

Connects to discussion in #417; please keep discussion in that issue. This issue is focused on implementation.

batch = GoodJob::Batch.new
batch.callback_class = "MyCallBackJob" # => Results in `MyCallbackJob.perform_later(batch)`
batch.callback_queue_name = "default"
batch.callback_priority = 0
batch.properties = { user: current_user } # additional state that is serialized/deserialized using ActiveJob/GlobalId
batch.add do
  MyJob.perform_later
  YourJob.perform_later
end

more_job = MoreJob.perform_later
batch.add(more_job)

batch.enqueue # jobs may be performed but the callback won't be triggered till `Batch#enqueue` is called

# Or more succinctly
GoodJob::Batch.enqueue(on_finish: "MyCallbackJob", user: current_user) do |batch|
  MyJob.perform_later
  YourJob.perform_later
  MoreJob.perform_later
end

batch.jobs # => All of the GoodJob::Jobs in the batch
batch.enqueued_at # => When the batch is first enqueued
batch.discarded_at # => When the _first_ job is discarded
batch.completed_at # => When all jobs are completed successfully or discarded

# When the _first_ job within the batch is discarded:
#   MyCallbackJob.perform_later(batch)
# When _all_ jobs within the batch are completed successfully or discarded:
#   MyCallbackJob.perform_later(batch)

Work

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

No branches or pull requests

1 participant