From c81edbc855ace48b1f62320a527e42903e3e20d4 Mon Sep 17 00:00:00 2001 From: Nick Elser Date: Wed, 6 May 2015 23:50:06 -0700 Subject: [PATCH] run GC sweeps more often since we most likely will have the time --- lib/zhong/job.rb | 13 +++++++++---- lib/zhong/scheduler.rb | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) 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