lib/clockwork.rb in clockwork-0.5.4 vs lib/clockwork.rb in clockwork-0.5.5

- old
+ new

@@ -15,11 +15,11 @@ def self.parse(at) return unless at case at when /^([[:alpha:]]+)\s(.*)$/ ret = parse($2) - wday = WDAYS.find_index {|x| x.include?($1) } + wday = WDAYS.find_index { |x| x.include?($1) } raise FailedToParse, at if wday.nil? ret.wday = wday ret when /^(\d{1,2}):(\d\d)$/ new($2.to_i, $1.to_i) @@ -67,13 +67,11 @@ else raise ArgumentError.new(':if expects a callable object, but #{options[:if]} does not respond to call') end end - if options[:thread] - @thread = options[:thread] - end + @thread = !!(options.has_key?(:thread) ? options[:thread] : Clockwork.config[:thread]) @timezone = options[:tz] || Clockwork.config[:tz] end def to_s @@ -92,20 +90,16 @@ def thread? @thread end - def thread_available? - Thread.list.count < Clockwork.config[:max_threads] - end - def run(t) t = convert_timezone(t) @last = t if thread? - if thread_available? + if Clockwork.thread_available? Thread.new { execute } else log_error "Threads exhausted; skipping #{self}" end else @@ -133,10 +127,14 @@ msg.join("\n") end end + def thread_available? + Thread.list.count < config[:max_threads] + end + def configure yield(config) end def config @@ -144,10 +142,10 @@ end extend self def default_configuration - { :sleep_timeout => 1, :logger => Logger.new(STDOUT), :max_threads => 10 } + { :sleep_timeout => 1, :logger => Logger.new(STDOUT), :thread => false, :max_threads => 10 } end @@configuration = default_configuration def handler(&block)