lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.5.1 vs lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.5.2

- old
+ new

@@ -93,10 +93,18 @@ end end alias job_id id + # Will fail with an ArgumentError if the job frequency is higher than + # the scheduler frequency. + # + def check_frequency + + # this parent implementation never fails + end + def trigger(time) @previous_time = @next_time set_next_time(time) @@ -541,10 +549,18 @@ ) if @frequency <= 0 set_next_time(nil) end + def check_frequency + + fail ArgumentError.new( + "job frequency (#{@frequency}s) is higher than " + + "scheduler frequency (#{@scheduler.frequency}s)" + ) if @frequency < @scheduler.frequency + end + protected def set_next_time(trigger_time, is_post=false) return if is_post @@ -618,12 +634,32 @@ @cron_line = opts[:_t] || ::Fugit::Cron.parse(cronline) set_next_time(nil) end + def check_frequency + + return if @scheduler.frequency <= 1 + # + # The minimum time delta in a cron job is 1 second, so if the + # scheduler frequency is less than that, no worries. + + f = @cron_line.rough_frequency + + fail ArgumentError.new( + "job frequency (min ~#{f}s) is higher than " + + "scheduler frequency (#{@scheduler.frequency}s)" + ) if f < @scheduler.frequency + end + def brute_frequency @cron_line.brute_frequency + end + + def rough_frequency + + @cron_line.rough_frequency end protected def set_next_time(trigger_time, is_post=false)