1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Add before_fork hooks option.

This is usefull to close database or other remote connections
that were opened during the preload_app phase of the master process.
This commit is contained in:
Nathan Samson 2015-08-06 02:03:36 +02:00
parent 2562379635
commit 6c4f788bb7
3 changed files with 18 additions and 0 deletions

View file

@ -379,6 +379,10 @@ module Puma
@cli.write_state
@master_read, @worker_write = read, @wakeup
hooks = @options[:before_fork]
hooks.each { |h| h.call }
spawn_workers
Signal.trap "SIGINT" do

View file

@ -19,6 +19,7 @@ module Puma
@options[:mode] ||= :http
@options[:binds] ||= []
@options[:on_restart] ||= []
@options[:before_fork] ||= []
@options[:before_worker_shutdown] ||= []
@options[:before_worker_boot] ||= []
@options[:before_worker_fork] ||= []

View file

@ -156,6 +156,19 @@ module Puma
@options[:workers] = count.to_i
end
# *Cluster mode only* Code to run immediately before master process
# forks workers (once on boot). These hooks can block if necessary
# to wait for background operations unknown to puma to finish before
# the process terminates.
# This can be used to close any connections to remote servers (database, redis, ...)
# that were opened when preloading the code
#
# This can be called multiple times to add hooks.
#
def before_fork(&block)
@options[:before_fork] << block
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