Skip to content

Commit

Permalink
re-implement auto cycle as a hook
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Apr 3, 2014
1 parent af66ce5 commit 5a14342
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 7 additions & 6 deletions 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
5 changes: 1 addition & 4 deletions lib/puma_auto_tune/hook.rb
Expand Up @@ -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

Expand Down

0 comments on commit 5a14342

Please sign in to comment.