Module: DispatchPolicy::ActiveJobPerformAllLaterPatch
- Defined in:
- lib/dispatch_policy/active_job_perform_all_later_patch.rb
Overview
Rails 7.1’s ActiveJob.perform_all_later(*jobs) bypasses ActiveJob::Base#enqueue and calls queue_adapter.enqueue_all directly. Dispatchable hooks on #enqueue, so without this patch the batch path would skip staging.
Instance Method Summary collapse
Instance Method Details
#perform_all_later(*jobs) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dispatch_policy/active_job_perform_all_later_patch.rb', line 8 def perform_all_later(*jobs) jobs.flatten! staged, remaining = jobs.partition do |job| klass = job.class klass.respond_to?(:dispatch_policy?) && klass.dispatch_policy? && DispatchPolicy.enabled? end staged_count = 0 staged.group_by(&:class).each do |klass, group| staged_count += DispatchPolicy::StagedJob.stage_many!( policy: klass.resolved_dispatch_policy, jobs: group ) end remaining_count = remaining.empty? ? 0 : super(*remaining) staged_count + remaining_count.to_i end |