Module: PumaWorkerKiller

Extended by:
PumaWorkerKiller
Included in:
PumaWorkerKiller
Defined in:
lib/puma_worker_killer.rb,
lib/puma_worker_killer/reaper.rb,
lib/puma_worker_killer/version.rb,
lib/puma_worker_killer/auto_reap.rb,
lib/puma_worker_killer/puma_memory.rb,
lib/puma_worker_killer/rolling_restart.rb

Defined Under Namespace

Classes: AutoReap, PumaMemory, Reaper, RollingRestart

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#frequencyObject

Returns the value of attribute frequency.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def frequency
  @frequency
end

#on_calculationObject

Returns the value of attribute on_calculation.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def on_calculation
  @on_calculation
end

#percent_usageObject

Returns the value of attribute percent_usage.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def percent_usage
  @percent_usage
end

#pre_termObject

Returns the value of attribute pre_term.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def pre_term
  @pre_term
end

#ramObject

Returns the value of attribute ram.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def ram
  @ram
end

#reaper_status_logsObject

Returns the value of attribute reaper_status_logs.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def reaper_status_logs
  @reaper_status_logs
end

#rolling_pre_termObject

Returns the value of attribute rolling_pre_term.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def rolling_pre_term
  @rolling_pre_term
end

#rolling_restart_frequencyObject

Returns the value of attribute rolling_restart_frequency.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def rolling_restart_frequency
  @rolling_restart_frequency
end

#rolling_restart_splay_secondsObject

Returns the value of attribute rolling_restart_splay_seconds.



8
9
10
# File 'lib/puma_worker_killer.rb', line 8

def rolling_restart_splay_seconds
  @rolling_restart_splay_seconds
end

Instance Method Details

#config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



22
23
24
# File 'lib/puma_worker_killer.rb', line 22

def config
  yield self
end

#enable_rolling_restart(frequency = rolling_restart_frequency, splay_seconds = rolling_restart_splay_seconds) ⇒ Object



35
36
37
38
39
40
# File 'lib/puma_worker_killer.rb', line 35

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

#reaper(ram = self.ram, percent_usage = self.percent_usage, reaper_status_logs = self.reaper_status_logs, pre_term = self.pre_term, on_calculation = self.on_calculation) ⇒ Object



26
27
28
# File 'lib/puma_worker_killer.rb', line 26

def reaper(ram = self.ram, percent_usage = self.percent_usage, reaper_status_logs = self.reaper_status_logs, pre_term = self.pre_term, on_calculation = self.on_calculation)
  Reaper.new(ram * percent_usage, nil, reaper_status_logs, pre_term, on_calculation)
end

#start(frequency = self.frequency, reaper = self.reaper) ⇒ Object



30
31
32
33
# File 'lib/puma_worker_killer.rb', line 30

def start(frequency = self.frequency, reaper = self.reaper)
  AutoReap.new(frequency, reaper).start
  enable_rolling_restart(rolling_restart_frequency) if rolling_restart_frequency
end