lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.3.4 vs lib/rufus/scheduler/jobs.rb in rufus-scheduler-3.4.0
- old
+ new
@@ -1,30 +1,6 @@
-#--
-# Copyright (c) 2006-2017, John Mettraux, jmettraux@gmail.com
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-#
-# Made in Japan.
-#++
-
module Rufus
class Scheduler
#--
@@ -84,11 +60,11 @@
@handler.method(:call) rescue nil
else
nil
end
- @scheduled_at = Rufus::Scheduler::ZoTime.now
+ @scheduled_at = EoTime.now
@unscheduled_at = nil
@last_time = nil
@locals = {}
@local_mutex = Mutex.new
@@ -130,18 +106,18 @@
# Trigger the job right now, off of its schedule.
#
# Done in collaboration with Piavka in
# https://github.com/jmettraux/rufus-scheduler/issues/214
#
- def trigger_off_schedule(time=Rufus::Scheduler::ZoTime.now)
+ def trigger_off_schedule(time=EoTime.now)
do_trigger(time)
end
def unschedule
- @unscheduled_at = Rufus::Scheduler::ZoTime.now
+ @unscheduled_at = EoTime.now
end
def threads
Thread.list.select { |t| t[:rufus_scheduler_job] == self }
@@ -197,11 +173,11 @@
#
# Warning: error rescueing is the responsibity of the caller.
#
def call(do_rescue=false)
- do_call(Rufus::Scheduler::ZoTime.now, do_rescue)
+ do_call(EoTime.now, do_rescue)
end
protected
def callback(meth, time)
@@ -264,11 +240,11 @@
end
end
def trigger_now(time)
- t = Rufus::Scheduler::ZoTime.now
+ t = EoTime.now
# if there are mutexes, t might be really bigger than time
Thread.current[:rufus_scheduler_job] = self
Thread.current[:rufus_scheduler_time] = t
Thread.current[:rufus_scheduler_timeout] = compute_timeout
@@ -278,11 +254,11 @@
do_call(time, true)
ensure
@last_work_time =
- Rufus::Scheduler::ZoTime.now - Thread.current[:rufus_scheduler_time]
+ EoTime.now - Thread.current[:rufus_scheduler_time]
@mean_work_time =
((@count - 1) * @mean_work_time + @last_work_time) / @count
post_trigger(time)
@@ -438,16 +414,17 @@
def first_at=(first)
return (@first_at = nil) if first == nil
- n0 = Rufus::Scheduler::ZoTime.now
+ n0 = EoTime.now
n1 = n0 + 0.003
first = n0 if first == :now || first == :immediately || first == 0
+ fdur = Rufus::Scheduler.parse_duration(first, no_error: true)
- @first_at = ZoTime.make(first)
+ @first_at = (fdur && (EoTime.now + fdur)) || EoTime.make(first)
@first_at = n1 if @first_at >= n0 && @first_at < n1
fail ArgumentError.new(
"cannot set first[_at|_in] in the past: " +
"#{first.inspect} -> #{@first_at.inspect}"
@@ -456,17 +433,22 @@
@first_at
end
def last_at=(last)
- #@last_at = last ? Rufus::Scheduler.parse_to_time(last) : nil
- @last_at = last ? ZoTime.make(last) : nil
+ @last_at =
+ if last
+ ldur = Rufus::Scheduler.parse_duration(last, no_error: true)
+ (ldur && (EoTime.now + ldur)) || EoTime.make(last)
+ else
+ nil
+ end
fail ArgumentError.new(
"cannot set last[_at|_in] in the past: " +
"#{last.inspect} -> #{@last_at.inspect}"
- ) if last && @last_at < Rufus::Scheduler::ZoTime.now
+ ) if last && @last_at < EoTime.now
@last_at
end
def trigger(time)
@@ -483,11 +465,11 @@
@times -= 1 if @times
end
def pause
- @paused_at = Rufus::Scheduler::ZoTime.now
+ @paused_at = EoTime.now
end
def resume
@paused_at = nil
@@ -562,11 +544,11 @@
def set_next_time(trigger_time, is_post=false)
return if is_post
- n = Rufus::Scheduler::ZoTime.now
+ n = EoTime.now
@next_time =
if @first_at && (trigger_time == nil || @first_at > n)
@first_at
else
@@ -602,13 +584,13 @@
def set_next_time(trigger_time, is_post=false)
@next_time =
if is_post
- Rufus::Scheduler::ZoTime.now + @interval
+ EoTime.now + @interval
elsif trigger_time.nil?
if @first_at == nil || @first_at < Time.now
- Rufus::Scheduler::ZoTime.now + @interval
+ EoTime.now + @interval
else
@first_at
end
else
false