mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Added on_worker_shutdown hook mechanism
This commit is contained in:
parent
55b9ce01e5
commit
e4ea4fb46d
3 changed files with 19 additions and 1 deletions
|
@ -99,6 +99,7 @@ module Puma
|
|||
:binds => [],
|
||||
:workers => 0,
|
||||
:daemon => false,
|
||||
:before_worker_shutdown => [],
|
||||
:before_worker_boot => [],
|
||||
:after_worker_boot => []
|
||||
}
|
||||
|
@ -228,7 +229,7 @@ module Puma
|
|||
|
||||
cfg = @config.dup
|
||||
|
||||
[ :logger, :before_worker_boot, :after_worker_boot, :on_restart ].each { |o| cfg.options.delete o }
|
||||
[ :logger, :before_worker_shutdown, :before_worker_boot, :after_worker_boot, :on_restart ].each { |o| cfg.options.delete o }
|
||||
|
||||
state["config"] = cfg
|
||||
|
||||
|
|
|
@ -216,6 +216,11 @@ module Puma
|
|||
|
||||
server.run.join
|
||||
|
||||
# Invoke any worker shutdown hooks so they can prevent the worker
|
||||
# exiting until any background operations are completed
|
||||
hooks = @options[:before_worker_shutdown]
|
||||
hooks.each { |h| h.call(index) }
|
||||
|
||||
ensure
|
||||
@worker_write.close
|
||||
end
|
||||
|
|
|
@ -21,6 +21,7 @@ module Puma
|
|||
@options[:mode] ||= :http
|
||||
@options[:binds] ||= []
|
||||
@options[:on_restart] ||= []
|
||||
@options[:before_worker_shutdown] ||= []
|
||||
@options[:before_worker_boot] ||= []
|
||||
@options[:after_worker_boot] ||= []
|
||||
@options[:worker_timeout] ||= DefaultWorkerTimeout
|
||||
|
@ -301,6 +302,17 @@ module Puma
|
|||
@options[:workers] = count.to_i
|
||||
end
|
||||
|
||||
# *Cluster mode only* Code to run immediately before a worker shuts
|
||||
# down (after it has finished processing HTTP requests). These hooks
|
||||
# can block if necessary to wait for background operations unknown
|
||||
# to puma to finish before the process terminates.
|
||||
#
|
||||
# This can be called multiple times to add hooks.
|
||||
#
|
||||
def on_worker_shutdown(&block)
|
||||
@options[:before_worker_shutdown] << block
|
||||
end
|
||||
|
||||
# *Cluster mode only* Code to run when a worker boots to setup
|
||||
# the process before booting the app.
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue