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

added after worker boot hook

This commit is contained in:
Max Gulyaev 2014-02-26 16:06:58 +02:00
parent e9bc323a83
commit e5150f0792
4 changed files with 26 additions and 5 deletions

View file

@ -113,6 +113,15 @@
# puts 'On worker boot...'
# end
# Code to run when a worker boots to setup the process after booting
# the app.
#
# This can be called multiple times to add hooks.
#
# after_worker_boot do
# puts 'On worker boot...'
# end
# === Puma control rack application ===
# Start the puma control rack application on “url”. This application can

View file

@ -99,7 +99,8 @@ module Puma
:binds => [],
:workers => 0,
:daemon => false,
:worker_boot => []
:before_worker_boot => [],
:after_worker_boot => []
}
@parser = OptionParser.new do |o|
@ -220,7 +221,7 @@ module Puma
cfg = @config.dup
[ :logger, :worker_boot, :on_restart ].each { |o| cfg.options.delete o }
[ :logger, :before_worker_boot, :after_worker_boot, :on_restart ].each { |o| cfg.options.delete o }
state["config"] = cfg

View file

@ -90,6 +90,7 @@ module Puma
pid = fork { worker(idx, upgrade, master) }
@cli.debug "Spawned worker: #{pid}"
@workers << Worker.new(idx, pid, @phase)
@options[:after_worker_boot].each { |h| h.call }
end
if diff > 0
@ -186,7 +187,7 @@ module Puma
# Invoke any worker boot hooks so they can get
# things in shape before booting the app.
hooks = @options[:worker_boot]
hooks = @options[:before_worker_boot]
hooks.each { |h| h.call(index) }
server = start_server

View file

@ -21,7 +21,8 @@ module Puma
@options[:mode] ||= :http
@options[:binds] ||= []
@options[:on_restart] ||= []
@options[:worker_boot] ||= []
@options[:before_worker_boot] ||= []
@options[:after_worker_boot] ||= []
@options[:worker_timeout] ||= DefaultWorkerTimeout
end
@ -306,7 +307,16 @@ module Puma
# This can be called multiple times to add hooks.
#
def on_worker_boot(&block)
@options[:worker_boot] << block
@options[:before_worker_boot] << block
end
# *Cluster mode only* Code to run when a worker boots to setup
# the process after booting the app.
#
# This can be called multiple times to add hooks.
#
def after_worker_boot(&block)
@options[:after_worker_boot] << block
end
# The directory to operate out of.