Class: PumaWorkerKiller::RollingRestart

Inherits:
Object
  • Object
show all
Defined in:
lib/puma_worker_killer/rolling_restart.rb

Instance Method Summary collapse

Constructor Details

#initialize(master = nil, rolling_pre_term = nil) ⇒ RollingRestart

Returns a new instance of RollingRestart.



5
6
7
8
# 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

Instance Method Details

#get_total_memoryObject

used for tes



11
12
13
# 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) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# 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