zombocom / puma_worker_killer

Automatically restart Puma cluster workers based on max RAM available
747 stars 77 forks source link

Add rolling_pre_term config #86

Closed adelnabiullin closed 4 years ago

adelnabiullin commented 4 years ago

Description

I was faced with the need to perform some actions on worker termination by rolling restart on Heroku. It turns out I'm not alone, see https://github.com/schneems/puma_worker_killer/issues/83 Existing pre_term config gives a possibility to such a thing, but only for termination caused by exceeding accepted RAM level.

This PR brings new config rolling_pre_term accepting a lambda (as pre_term) that will be called just prior to worker termination by rolling restart when rolling restart is enabled.

Usage

PumaWorkerKiller.config do |config|
  config.rolling_pre_term = lambda do |worker|
    puts "Terminating worker #{worker.pid} at #{Time.now}"
  end
end
adelnabiullin commented 4 years ago

Looks like PR #81 (latest merged to master) did not pass tests against ruby version 2.3.8 because Array#sum does not exist in ruby 2.3.8 Maybe it makes sense to implement some workaround considering different ruby versions or just remove tests against 2.3.8 from CI?

schneems commented 4 years ago

Can you send me a PR to fix the suite? You can use inject(&:+) instead of sum

On Thu, Jun 11, 2020 at 5:52 PM Adel Nabiullin notifications@github.com wrote:

Looks like PR #81 https://github.com/schneems/puma_worker_killer/pull/81 (latest merged to master) did not pass test against ruby version 2.3.8 because Array#sum does not exist in ruby 2.3.8 Maybe it makes sense to implement some workaround considering different ruby versions or just remove tests against 2.3.8 from CI?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/schneems/puma_worker_killer/pull/86#issuecomment-642970359, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAOSYER4XBMXZDGA7UJXY3RWFN4TANCNFSM4N3YYTLA .

-- Richard Schneeman https://www.schneems.com he/him

adelnabiullin commented 4 years ago

@schneems done

schneems commented 4 years ago

This is released in 0.2.0 thanks!