lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.0.4 vs lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.0.5
- old
+ new
@@ -181,10 +181,19 @@
# o.class == self.class && o.hash == self.hash
#end
#
# might be necessary at some point
+ # Calls the callable (usually a block) wrapped in this Job instance.
+ #
+ # Warning: error rescueing is the responsibity of the caller.
+ #
+ def call(do_rescue=false)
+
+ do_call(Time.now, do_rescue)
+ end
+
protected
def callback(meth, time)
return true unless @scheduler.respond_to?(meth)
@@ -207,10 +216,26 @@
def mutex(m)
m.is_a?(Mutex) ? m : (@scheduler.mutexes[m.to_s] ||= Mutex.new)
end
+ def do_call(time, do_rescue)
+
+ args = [ self, time ][0, @callable.arity]
+ @callable.call(*args)
+
+ rescue StandardError => se
+
+ raise se unless do_rescue
+
+ return if se.is_a?(KillSignal) # discard
+
+ @scheduler.on_error(self, se)
+
+ # exceptions above StandardError do pass through
+ end
+
def do_trigger(time)
t = Time.now
# if there are mutexes, t might be really bigger than time
@@ -218,21 +243,12 @@
Thread.current[:rufus_scheduler_time] = t
Thread.current[:rufus_scheduler_timeout] = compute_timeout
@last_time = t
- args = [ self, time ][0, @callable.arity]
- @callable.call(*args)
+ do_call(time, true)
- rescue KillSignal
-
- # discard
-
- rescue StandardError => se
-
- @scheduler.on_error(self, se)
-
ensure
post_trigger(time)
Thread.current[:rufus_scheduler_job] = nil
@@ -366,22 +382,27 @@
raise 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_at] || opts[:first_in] || 0
+ opts[:first] || opts[:first_time] ||
+ opts[:first_at] || opts[:first_in] ||
+ 0
self.last_at =
opts[:last] || opts[:last_at] || opts[:last_in]
end
def first_at=(first)
+ n = Time.now
+ first = n + 0.001 if first == :now || first == :immediately
+
@first_at = Rufus::Scheduler.parse_to_time(first)
raise ArgumentError.new(
"cannot set first[_at|_in] in the past: " +
"#{first.inspect} -> #{@first_at.inspect}"
- ) if first != 0 && @first_at < Time.now
+ ) if first != 0 && @first_at < n
end
def last_at=(last)
@last_at = last ? Rufus::Scheduler.parse_to_time(last) : nil