lib/rufus/scheduler.rb in rufus-scheduler-3.3.4 vs lib/rufus/scheduler.rb in rufus-scheduler-3.4.0

- old
+ new

@@ -1,48 +1,28 @@ -#-- -# 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. -#++ +require 'set' require 'date' if RUBY_VERSION < '1.9.0' require 'time' require 'thread' -require 'tzinfo' +require 'et-orbi' + module Rufus class Scheduler + VERSION = '3.4.0' + + EoTime = ::EtOrbi::EoTime + require 'rufus/scheduler/util' - require 'rufus/scheduler/zotime' require 'rufus/scheduler/jobs' require 'rufus/scheduler/cronline' require 'rufus/scheduler/job_array' require 'rufus/scheduler/locks' - VERSION = '3.3.4' - # # A common error class for rufus-scheduler # class Error < StandardError; end @@ -102,11 +82,11 @@ end @trigger_lock = opts[:trigger_lock] || Rufus::Scheduler::NullLock.new # If we can't grab the @scheduler_lock, don't run. - @scheduler_lock.lock || return + lock || return start end # Returns a singleton Rufus::Scheduler instance @@ -152,16 +132,16 @@ alias stop shutdown def uptime - @started_at ? Rufus::Scheduler::ZoTime.now - @started_at : nil + @started_at ? EoTime.now - @started_at : nil end def uptime_s - self.class.to_duration(uptime) + uptime ? self.class.to_duration(uptime) : '' end def join fail NotRunningError.new( @@ -407,11 +387,11 @@ # block code) # # Accepts a query option, which can be set to: # * :all (default), returns all the threads that are work threads # or are currently running a job - # * :active, returns all threads that are currenly running a job + # * :active, returns all threads that are currently running a job # * :vacant, returns the threads that are not running a job # # If, thanks to :blocking => true, a job is scheduled to monopolize the # main scheduler thread, that thread will get returned when :active or # :all. @@ -476,11 +456,13 @@ stderr.puts(" #{pre} #{l}") end stderr.puts(" #{pre} tz:") stderr.puts(" #{pre} ENV['TZ']: #{ENV['TZ']}") stderr.puts(" #{pre} Time.now: #{Time.now}") - stderr.puts(" #{pre} local_tzone: #{Rufus::Scheduler::ZoTime.local_tzone.inspect}") + stderr.puts(" #{pre} local_tzone: #{EoTime.local_tzone.inspect}") + stderr.puts(" #{pre} et-orbi:") + stderr.puts(" #{pre} #{EoTime.platform_info}") stderr.puts(" #{pre} scheduler:") stderr.puts(" #{pre} object_id: #{object_id}") stderr.puts(" #{pre} opts:") stderr.puts(" #{pre} #{@opts.inspect}") stderr.puts(" #{pre} frequency: #{self.frequency}") @@ -556,11 +538,11 @@ # work_threads.each { |t| t.raise(KillSignal) } #end def start - @started_at = Rufus::Scheduler::ZoTime.now + @started_at = EoTime.now @thread = Thread.new do while @started_at do @@ -583,11 +565,11 @@ @jobs.delete_unscheduled end def trigger_jobs - now = Rufus::Scheduler::ZoTime.now + now = EoTime.now @jobs.each(now) do |job| job.trigger(now) end @@ -602,12 +584,12 @@ ts = t[:rufus_scheduler_time] next unless job && to && ts # thread might just have become inactive (job -> nil) - to = ts + to unless to.is_a?(Rufus::Scheduler::ZoTime) + to = ts + to unless to.is_a?(EoTime) - next if to > Rufus::Scheduler::ZoTime.now + next if to > EoTime.now t.raise(Rufus::Scheduler::TimeoutError) end end