Skip to content

Commit

Permalink
Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Aug 18, 2020
1 parent bbe1207 commit a5b49ab
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
7 changes: 5 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ Style/Documentation:

Style/HashSyntax:
Enabled: false

Style/ModuleFunction:
Enabled: false

Style/StringLiterals:
EnforcedStyle: single_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Gemspec/RequiredRubyVersion:
Enabled: false
4 changes: 2 additions & 2 deletions lib/puma_worker_killer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def start(frequency = self.frequency, reaper = self.reaper)
enable_rolling_restart(rolling_restart_frequency) if rolling_restart_frequency
end

def enable_rolling_restart(frequency = self.rolling_restart_frequency)
def enable_rolling_restart(frequency = rolling_restart_frequency)
frequency += rand(0..10.0) # so all workers don't restart at the exact same time across multiple machines
AutoReap.new(frequency, RollingRestart.new(nil, self.rolling_pre_term)).start
AutoReap.new(frequency, RollingRestart.new(nil, rolling_pre_term)).start
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puma_worker_killer/rolling_restart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def reap(seconds_between_worker_kill = 60)

@cluster.workers.each do |worker, _ram|
@cluster.master.log "PumaWorkerKiller: Rolling Restart. #{@cluster.workers.count} workers consuming total: #{total_memory} mb. Sending TERM to pid #{worker.pid}."
@rolling_pre_term.call(worker) unless @rolling_pre_term.nil?
@rolling_pre_term&.call(worker)

worker.term
sleep seconds_between_worker_kill
Expand Down
6 changes: 4 additions & 2 deletions test/fixtures/rolling_pre_term.ru
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
load File.expand_path("../fixture_helper.rb", __FILE__)
# frozen_string_literal: true

load File.expand_path('fixture_helper.rb', __dir__)

PumaWorkerKiller.config do |config|
config.rolling_pre_term = lambda { |worker| puts("About to terminate (rolling) worker: #{worker.pid}") }
config.rolling_pre_term = ->(worker) { puts("About to terminate (rolling) worker: #{worker.pid}") }
end
PumaWorkerKiller.enable_rolling_restart(1) # 1 second

Expand Down
10 changes: 5 additions & 5 deletions test/puma_worker_killer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ def test_rolling_restart_worker_kill_check
end

def test_rolling_pre_term
file = fixture_path.join("rolling_pre_term.ru")
file = fixture_path.join('rolling_pre_term.ru')
port = 0
command = "bundle exec puma #{ file } -t 1:1 -w 2 --preload --debug -p #{ port }"
command = "bundle exec puma #{file} -t 1:1 -w 2 --preload --debug -p #{port}"
puts command.inspect
options = { wait_for: "booted", timeout: 15, env: { } }
options = { wait_for: 'booted', timeout: 15, env: {} }

WaitForIt.new(command, options) do |spawn|
assert_contains(spawn, "Rolling Restart")
assert_contains(spawn, "About to terminate (rolling) worker:") # defined in rolling_pre_term.ru
assert_contains(spawn, 'Rolling Restart')
assert_contains(spawn, 'About to terminate (rolling) worker:') # defined in rolling_pre_term.ru
end
end
end

0 comments on commit a5b49ab

Please sign in to comment.