Sha256: 177b49ddad5c7d55dcccb1cb2f0c29896d955538e046efea3998a5a084348bd8

Contents?: true

Size: 854 Bytes

Versions: 4

Compression:

Stored size: 854 Bytes

Contents

# frozen_string_literal: true

module PumaWorkerKiller
  class RollingRestart
    def initialize(master = nil, rolling_pre_term = nil)
      @cluster = PumaWorkerKiller::PumaMemory.new(master)
      @rolling_pre_term = rolling_pre_term
    end

    # used for tes
    def get_total_memory
      @cluster.get_total_memory
    end

    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puma_worker_killer-1.0.0 lib/puma_worker_killer/rolling_restart.rb
puma_worker_killer-0.3.1 lib/puma_worker_killer/rolling_restart.rb
puma_worker_killer-0.3.0 lib/puma_worker_killer/rolling_restart.rb
puma_worker_killer-0.2.0 lib/puma_worker_killer/rolling_restart.rb