lib/rufus/scheduler.rb in rufus-scheduler-3.0.1 vs lib/rufus/scheduler.rb in rufus-scheduler-3.0.2
- old
+ new
@@ -36,20 +36,31 @@
require 'rufus/scheduler/util'
require 'rufus/scheduler/jobs'
require 'rufus/scheduler/cronline'
require 'rufus/scheduler/job_array'
- VERSION = '3.0.1'
+ VERSION = '3.0.2'
#
+ # A common error class for rufus-scheduler
+ #
+ class Error < StandardError; end
+
+ #
# This error is thrown when the :timeout attribute triggers
#
- class TimeoutError < StandardError; end
+ class TimeoutError < Error; end
- #MIN_WORK_THREADS = 7
- MAX_WORK_THREADS = 35
+ #
+ # For when the scheduler is not running
+ # (it got shut down or didn't start because of a lock)
+ #
+ class NotRunningError < Error; end
+ #MIN_WORK_THREADS = 3
+ MAX_WORK_THREADS = 28
+
attr_accessor :frequency
attr_reader :started_at
attr_reader :thread
attr_reader :thread_key
attr_reader :mutexes
@@ -138,10 +149,14 @@
self.class.to_duration(uptime)
end
def join
+ fail NotRunningError.new(
+ 'cannot join scheduler that is not running'
+ ) unless @thread
+
@thread.join
end
def paused?
@@ -500,10 +515,10 @@
end
end
def do_schedule(job_type, t, callable, opts, return_job_instance, block)
- raise RuntimeError.new(
+ fail NotRunningError.new(
'cannot schedule, scheduler is down or shutting down'
) if @started_at == nil
callable, opts = nil, callable if callable.is_a?(Hash)
return_job_instance ||= opts[:job]