Module: RocketJob::Batch::ThrottleWindows
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rocket_job/batch/throttle_windows.rb
Overview
For a batch job that can run over a long period of time it can be useful to prevent its slices from being processed outside a predefined processing window.
This plugin supports up to 2 different processing windows.
For example, do not run this job during business hours. Allow it to run from 5pm until 8am the following day Mon through Fri.
class AfterHoursJob < RocketJob::Job
include RocketJob::Batch
include RocketJob::Batch::ThrottleWindows
# Monday through Thursday the job can start processing at 5pm Eastern.
self.primary_schedule = "0 17 * * 1-4 America/New_York"
# Slices are allowed to run until 8am the following day, which is 15 hours long:
self.primary_duration = 15.hours
# The slices for this job can run all weekend long, starting Friday at 5pm Eastern.
self.secondary_schedule = "0 17 * * 5 America/New_York"
# Slices are allowed to run until 8am on Monday morning, which is 63 hours long:
self.secondary_duration = 63.hours
end
Notes:
-
These schedules do not affect when the job is started, completed, or when ‘before_batch` or `after_batch` processing is performed. It only limits when individual slices are processed.