lib/rocket_job/plugins/processing_window.rb in rocketjob-5.3.0 vs lib/rocket_job/plugins/processing_window.rb in rocketjob-5.3.1
- old
+ new
@@ -1,6 +1,7 @@
require "active_support/concern"
+require "fugit"
module RocketJob
module Plugins
# Ensure that a job will only run between certain hours of the day, regardless of when it was
# created/enqueued. Useful for creating a job now that should only be processed later during a
@@ -45,42 +46,35 @@
before_retry :rocket_job_processing_window_set_run_at
after_start :rocket_job_processing_window_check
validates_presence_of :processing_schedule, :processing_duration
validates_each :processing_schedule do |record, attr, value|
- begin
- RocketJob::Plugins::Rufus::CronLine.new(value)
- rescue ArgumentError => e
- record.errors.add(attr, e.message)
- end
+ record.errors.add(attr, "Invalid schedule: #{value.inspect}") unless Fugit::Cron.new(value)
end
end
# Returns [true|false] whether this job is currently inside its processing window
def rocket_job_processing_window_active?
- time = Time.now
- previous_time = rocket_job_processing_schedule.previous_time(time)
+ time = Time.now.utc
+ previous_time = Fugit::Cron.new(processing_schedule).previous_time(time).to_utc_time
# Inside previous processing window?
previous_time + processing_duration > time
end
private
# Only process this job if it is still in its processing window
def rocket_job_processing_window_check
return if rocket_job_processing_window_active?
- logger.warn("Processing window closed before job was processed. Job is re-scheduled to run at: #{rocket_job_processing_schedule.next_time}")
+ next_time = Fugit::Cron.new(processing_schedule).next_time.to_utc_time
+ logger.warn("Processing window closed before job was processed. Job is re-scheduled to run at: #{next_time}")
self.worker_name ||= "inline"
requeue!(worker_name)
end
def rocket_job_processing_window_set_run_at
- self.run_at = rocket_job_processing_schedule.next_time unless rocket_job_processing_window_active?
- end
-
- def rocket_job_processing_schedule
- RocketJob::Plugins::Rufus::CronLine.new(processing_schedule)
+ self.run_at = Fugit::Cron.new(processing_schedule).next_time.to_utc_time unless rocket_job_processing_window_active?
end
end
end
end