lib/rocket_job/batch/throttle_windows.rb in rocketjob-5.3.0 vs lib/rocket_job/batch/throttle_windows.rb in rocketjob-5.3.1

- old
+ new

@@ -1,6 +1,7 @@ require "active_support/concern" +require "fugit" module RocketJob module Batch # 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. @@ -41,10 +42,14 @@ field :secondary_schedule, type: String, class_attribute: true, user_editable: true, copy_on_restart: true # Duration in seconds of the secondary window. field :secondary_duration, type: Integer, class_attribute: true, user_editable: true, copy_on_restart: true define_batch_throttle :throttle_windows_exceeded?, filter: :throttle_filter_id + + validates_each :primary_schedule, :secondary_schedule do |record, attr, value| + record.errors.add(attr, "Invalid #{attr}: #{value.inspect}") if value && !Fugit::Cron.new(value) + end end private def throttle_windows_exceeded? @@ -54,13 +59,13 @@ end exceeded end def throttle_outside_window?(schedule, duration) - cron = Plugins::Rufus::CronLine.new(schedule) - time = Time.now + 1 + cron = Fugit::Cron.new(schedule) + time = Time.now.utc + 1 # Add 1 second since right now could be the very beginning of the processing window. - previous_time = cron.previous_time(time).to_time + previous_time = cron.previous_time(time).to_utc_time previous_time + duration < time end end end end