lib/rufus/scheduler.rb in rufus-scheduler-3.0.6 vs lib/rufus/scheduler.rb in rufus-scheduler-3.0.7

- old
+ new

@@ -36,11 +36,11 @@ require 'rufus/scheduler/util' require 'rufus/scheduler/jobs' require 'rufus/scheduler/cronline' require 'rufus/scheduler/job_array' - VERSION = '3.0.6' + VERSION = '3.0.7' # # A common error class for rufus-scheduler # class Error < StandardError; end @@ -368,23 +368,76 @@ def running_jobs(opts={}) jobs(opts.merge(:running => true)) end + def occurrences(time0, time1, format=:per_job) + + h = {} + + jobs.each do |j| + os = j.occurrences(time0, time1) + h[j] = os if os.any? + end + + if format == :timeline + a = [] + h.each { |j, ts| ts.each { |t| a << [ t, j ] } } + a.sort_by { |(t, j)| t } + else + h + end + end + + def timeline(time0, time1) + + occurrences(time0, time1, :timeline) + end + def on_error(job, err) pre = err.object_id.to_s + ms = {}; mutexes.each { |k, v| ms[k] = v.locked? } + stderr.puts("{ #{pre} rufus-scheduler intercepted an error:") stderr.puts(" #{pre} job:") stderr.puts(" #{pre} #{job.class} #{job.original.inspect} #{job.opts.inspect}") + # TODO: eventually use a Job#detail or something like that stderr.puts(" #{pre} error:") stderr.puts(" #{pre} #{err.object_id}") stderr.puts(" #{pre} #{err.class}") stderr.puts(" #{pre} #{err}") err.backtrace.each do |l| 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} scheduler:") + stderr.puts(" #{pre} object_id: #{object_id}") + stderr.puts(" #{pre} opts:") + stderr.puts(" #{pre} #{@opts.inspect}") + stderr.puts(" #{pre} frequency: #{self.frequency}") + stderr.puts(" #{pre} lockfile: #{@lockfile.inspect}") + stderr.puts(" #{pre} uptime: #{uptime} (#{uptime_s})") + stderr.puts(" #{pre} down?: #{down?}") + stderr.puts(" #{pre} threads: #{self.threads.size}") + stderr.puts(" #{pre} thread: #{self.thread}") + stderr.puts(" #{pre} thread_key: #{self.thread_key}") + stderr.puts(" #{pre} work_threads: #{work_threads.size}") + stderr.puts(" #{pre} active: #{work_threads(:active).size}") + stderr.puts(" #{pre} vacant: #{work_threads(:vacant).size}") + stderr.puts(" #{pre} max_work_threads: #{max_work_threads}") + stderr.puts(" #{pre} mutexes: #{ms.inspect}") + stderr.puts(" #{pre} jobs: #{jobs.size}") + stderr.puts(" #{pre} at_jobs: #{at_jobs.size}") + stderr.puts(" #{pre} in_jobs: #{in_jobs.size}") + stderr.puts(" #{pre} every_jobs: #{every_jobs.size}") + stderr.puts(" #{pre} interval_jobs: #{interval_jobs.size}") + stderr.puts(" #{pre} cron_jobs: #{cron_jobs.size}") + stderr.puts(" #{pre} running_jobs: #{running_jobs.size}") + stderr.puts(" #{pre} work_queue: #{work_queue.size}") stderr.puts("} #{pre} .") rescue => e stderr.puts("failure in #on_error itself:")