class PumaWorkerKiller::RollingRestart

Public Class Methods

new(master = nil, rolling_pre_term = nil) click to toggle source
# File lib/puma_worker_killer/rolling_restart.rb, line 5
def initialize(master = nil, rolling_pre_term = nil)
  @cluster = PumaWorkerKiller::PumaMemory.new(master)
  @rolling_pre_term = rolling_pre_term
end

Public Instance Methods

get_total_memory() click to toggle source

used for tes

# File lib/puma_worker_killer/rolling_restart.rb, line 11
def get_total_memory
  @cluster.get_total_memory
end
reap(seconds_between_worker_kill = 60) click to toggle source
# File lib/puma_worker_killer/rolling_restart.rb, line 15
def reap(seconds_between_worker_kill = 60)
  # this will implicitly call set_workers
  total_memory = get_total_memory
  return false unless @cluster.running?

  @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)

    worker.term
    sleep seconds_between_worker_kill
  end
end