diff --git a/lib/zhong/job.rb b/lib/zhong/job.rb index 1bdd11b..4323e5e 100644 --- a/lib/zhong/job.rb +++ b/lib/zhong/job.rb @@ -40,15 +40,20 @@ def run(time = Time.now) end @thread = nil + locked = false + + @lock.lock do + locked = true - ran_set = @lock.lock do refresh_last_ran - break true unless run?(time) + # we need to check again, as another process might have acquired + # the lock right before us and obviated our need to do anything + break unless run?(time) if disabled? @logger.info "disabled: #{self}" - break true + break end @logger.info "running: #{self}" @@ -58,7 +63,7 @@ def run(time = Time.now) ran!(time) end - @logger.info "unable to acquire exclusive run lock: #{self}" unless ran_set + @logger.info "unable to acquire exclusive run lock: #{self}" unless locked end def stop diff --git a/lib/zhong/scheduler.rb b/lib/zhong/scheduler.rb index 3581df8..69ab49b 100644 --- a/lib/zhong/scheduler.rb +++ b/lib/zhong/scheduler.rb @@ -63,6 +63,8 @@ def start fire_callbacks(:after_tick) + GC.start + sleep(interval) end