lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.1.9 vs lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.1.10
- old
+ new
@@ -89,11 +89,11 @@
@locals = {}
@local_mutex = Mutex.new
@id = determine_id
- raise(
+ fail(
ArgumentError,
'missing block or callable to schedule',
caller[2..-1]
) unless @callable
@@ -233,11 +233,11 @@
args = [ self, time ][0, @callable.arity]
@callable.call(*args)
rescue StandardError => se
- raise se unless do_rescue
+ fail se unless do_rescue
return if se.is_a?(KillSignal) # discard
@scheduler.on_error(self, se)
@@ -400,11 +400,11 @@
@paused_at = nil
@times = opts[:times]
- raise ArgumentError.new(
+ fail ArgumentError.new(
"cannot accept :times => #{@times.inspect}, not nil or an int"
) unless @times == nil || @times.is_a?(Fixnum)
self.first_at =
opts[:first] || opts[:first_time] ||
@@ -414,31 +414,38 @@
opts[:last] || opts[:last_at] || opts[:last_in]
end
def first_at=(first)
- return @first_at = nil if first == nil
+ return (@first_at = nil) if first == nil
- n = Time.now
- first = n + 0.003 if first == :now || first == :immediately
+ n0 = Time.now
+ n1 = n0 + 0.003
+ first = n0 if first == :now || first == :immediately || first == 0
+
@first_at = Rufus::Scheduler.parse_to_time(first)
+ @first_at = n1 if @first_at >= n0 && @first_at < n1
- raise ArgumentError.new(
+ fail ArgumentError.new(
"cannot set first[_at|_in] in the past: " +
"#{first.inspect} -> #{@first_at.inspect}"
- ) if first != 0 && @first_at < n
+ ) if @first_at < n0
+
+ @first_at
end
def last_at=(last)
@last_at = last ? Rufus::Scheduler.parse_to_time(last) : nil
- raise ArgumentError.new(
+ fail ArgumentError.new(
"cannot set last[_at|_in] in the past: " +
"#{last.inspect} -> #{@last_at.inspect}"
) if last && @last_at < Time.now
+
+ @last_at
end
def trigger(time)
return if @paused_at
@@ -520,11 +527,11 @@
super(scheduler, duration, opts, block)
@frequency = Rufus::Scheduler.parse_in(@original)
- raise ArgumentError.new(
+ fail ArgumentError.new(
"cannot schedule #{self.class} with a frequency " +
"of #{@frequency.inspect} (#{@original.inspect})"
) if @frequency <= 0
set_next_time(nil)
@@ -558,10 +565,10 @@
super(scheduler, interval, opts, block)
@interval = Rufus::Scheduler.parse_in(@original)
- raise ArgumentError.new(
+ fail ArgumentError.new(
"cannot schedule #{self.class} with an interval " +
"of #{@interval.inspect} (#{@original.inspect})"
) if @interval <= 0
set_next_time(nil)