module RocketJob::Batch::LowerPriority
Automatically lower the priority for Jobs
with a higher record_count.
Note:
- Add `:lower_priority` as a before_batch, but only once the `record_count` has been set. - If the `record_count` is not set by the time this plugins `before_batch` is called, then the priority will not be modified.
class SampleJob < RocketJob::Job
include RocketJob::Plugins::Batch include RocketJob::Plugins::Batch::LowerPriority before_batch :upload_data, :lower_priority def perform(record) record.reverse end private def upload_data upload do |stream| stream << 'abc' stream << 'def' stream << 'ghi' end end
end
Private Instance Methods
lower_priority()
click to toggle source
# File lib/rocket_job/batch/lower_priority.rb, line 46 def lower_priority return unless record_count new_priority = priority + (record_count.to_f / lower_priority_count).to_i self.priority = [new_priority, 100].min end