lib/zhong/job.rb in zhong-0.1.5 vs lib/zhong/job.rb in zhong-0.1.6

- old
+ new

@@ -9,11 +9,11 @@ @config = config @at = config[:at] ? At.parse(config[:at], grace: config.fetch(:grace, 15.minutes)) : nil @every = config[:every] ? Every.parse(config[:every]) : nil - fail "must specific either `at` or `every` for job: #{self}" unless @at || @every + raise "must specific either `at` or `every` for job: #{self}" unless @at || @every @block = block @redis = config[:redis] @tz = config[:tz] @@ -37,10 +37,11 @@ def run(time = Time.now, error_handler = nil) return unless run?(time) locked = false errored = false + ran = false begin redis_lock.lock do locked = true @running = true @@ -59,10 +60,11 @@ logger.info "running: #{self}" if @block begin @block.call + ran = true rescue => boom logger.error "#{self} failed: #{boom}" error_handler.call(boom, self) if error_handler end end @@ -75,10 +77,12 @@ end @running = false logger.info "unable to acquire exclusive run lock: #{self}" if !locked && !errored + + ran end def running? @running end @@ -95,10 +99,10 @@ def enable @redis.del(disabled_key) end def disabled? - !!@redis.get(disabled_key) + !@redis.get(disabled_key).nil? end def to_s @to_s ||= [@category, @name].compact.join(".").freeze end