From 5a14342ae567437330a3ad0d2e489e5402a70120 Mon Sep 17 00:00:00 2001 From: schneems Date: Thu, 3 Apr 2014 16:14:33 -0400 Subject: [PATCH] re-implement auto cycle as a hook --- lib/puma_auto_tune/defaults/ram/wrappers.rb | 13 +++++++------ lib/puma_auto_tune/hook.rb | 5 +---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/puma_auto_tune/defaults/ram/wrappers.rb b/lib/puma_auto_tune/defaults/ram/wrappers.rb index 9159391..0a2eee1 100644 --- a/lib/puma_auto_tune/defaults/ram/wrappers.rb +++ b/lib/puma_auto_tune/defaults/ram/wrappers.rb @@ -1,19 +1,20 @@ PumaAutoTune.hooks(:ram) do |auto| - auto.wrap(:reap_cycle) do |block| + auto.wrap(:reap_cycle) do |orig| Proc.new do |resource, master, workers| ends_at = Time.now + PumaAutoTune.reap_duration while Time.now < ends_at sleep 1 - block.call(*auto.args) + orig.call(*auto.args) end end end - auto.wrap(:remove_worker) do |block| + auto.wrap(:cycle) do |orig| Proc.new do |resource, master, workers| - resource.reset - PumaAutoTune.max_worker_limit = workers.size - 1 - block.call(*auto.args) + loop do + sleep PumaAutoTune.frequency + orig.call(*auto.args) if master.running? + end end end end diff --git a/lib/puma_auto_tune/hook.rb b/lib/puma_auto_tune/hook.rb index bfcb10f..b94306a 100644 --- a/lib/puma_auto_tune/hook.rb +++ b/lib/puma_auto_tune/hook.rb @@ -32,10 +32,7 @@ def wrap_hook(name, &block) def auto_cycle Thread.new do - loop do - sleep PumaAutoTune.frequency - call(:cycle) if @resource.master.running? - end + self.call(:cycle) end end