lib/rufus/scheduler.rb in rufus-scheduler-3.4.2 vs lib/rufus/scheduler.rb in rufus-scheduler-3.5.0
- old
+ new
@@ -2,24 +2,23 @@
require 'set'
require 'date' if RUBY_VERSION < '1.9.0'
require 'time'
require 'thread'
-require 'et-orbi'
+require 'fugit'
module Rufus
class Scheduler
- VERSION = '3.4.2'
+ VERSION = '3.5.0'
EoTime = ::EtOrbi::EoTime
require 'rufus/scheduler/util'
require 'rufus/scheduler/jobs'
- require 'rufus/scheduler/cronline'
require 'rufus/scheduler/job_array'
require 'rufus/scheduler/locks'
#
# A common error class for rufus-scheduler
@@ -236,13 +235,13 @@
opts = opts.dup
opts[:_t] = Scheduler.parse(arg, opts)
case opts[:_t]
- when CronLine then schedule_cron(arg, callable, opts, &block)
- when Time then schedule_at(arg, callable, opts, &block)
- else schedule_in(arg, callable, opts, &block)
+ when ::Fugit::Cron then schedule_cron(arg, callable, opts, &block)
+ when ::EtOrbi::EoTime, Time then schedule_at(arg, callable, opts, &block)
+ else schedule_in(arg, callable, opts, &block)
end
end
def repeat(arg, callable=nil, opts={}, &block)
@@ -250,12 +249,12 @@
opts = opts.dup
opts[:_t] = Scheduler.parse(arg, opts)
case opts[:_t]
- when CronLine then schedule_cron(arg, callable, opts, &block)
- else schedule_every(arg, callable, opts, &block)
+ when ::Fugit::Cron then schedule_cron(arg, callable, opts, &block)
+ else schedule_every(arg, callable, opts, &block)
end
end
def unschedule(job_or_job_id)
@@ -618,13 +617,38 @@
CronJob
end
job = job_class.new(self, t, opts, block || callable)
- fail ArgumentError.new(
- "job frequency (#{job.frequency}) is higher than " +
- "scheduler frequency (#{@frequency})"
- ) if job.respond_to?(:frequency) && job.frequency < @frequency
+ #fail ArgumentError.new(
+ # "job frequency (#{job.frequency}) is higher than " +
+ # "scheduler frequency (#{@frequency})"
+ #) if job.respond_to?(:frequency) && job.frequency < @frequency
+ #
+ # This was expensive
+
+ if (
+ ! job.is_a?(Rufus::Scheduler::IntervalJob) &&
+ job.methods.include?(:next_time_from)
+ ) then
+
+ nts = (1..365)
+ .inject([ job.send(:next_time_from, EtOrbi.now) ]) { |a, i|
+ a << job.send(:next_time_from, a.last); a }
+ deltas = []; prev = nts.shift
+ while (nt = nts.shift); deltas << (nt - prev).to_f; prev = nt; end
+
+ deltas = deltas[1..-1] \
+ if opts.keys.find { |k| k.to_s.match(/\Afirst/) }
+ #
+ # do not consider the first delta if there is a first, first_at,
+ # or first_in involved
+
+ fail ArgumentError.new(
+ "job frequency (~max #{deltas.min}s) is higher than " +
+ "scheduler frequency (#{@frequency})"
+ ) if deltas.min < @frequency * 0.9
+ end
@jobs.push(job)
return_job_instance ? job : job.job_id
end