lib/pitchfork/configurator.rb in pitchfork-0.10.0 vs lib/pitchfork/configurator.rb in pitchfork-0.11.0
- old
+ new
@@ -32,13 +32,15 @@
DEFAULTS = {
:soft_timeout => 20,
:cleanup_timeout => 2,
:spawn_timeout => 10,
+ :timeout_signal => -> (_pid) { :KILL },
:timeout => 22,
:logger => default_logger,
:worker_processes => 1,
+ :before_fork => nil,
:after_worker_fork => lambda { |server, worker|
server.logger.info("worker=#{worker.nr} gen=#{worker.generation} pid=#{$$} spawned")
},
:after_mold_fork => lambda { |server, worker|
server.logger.info("mold gen=#{worker.generation} pid=#{$$} spawned")
@@ -131,10 +133,14 @@
end
set[:logger] = obj
end
+ def before_fork(*args, &block)
+ set_hook(:before_fork, block_given? ? block : args[0], 1)
+ end
+
def after_worker_fork(*args, &block)
set_hook(:after_worker_fork, block_given? ? block : args[0])
end
def after_mold_fork(*args, &block)
@@ -171,9 +177,22 @@
def timeout(seconds, cleanup: 2)
soft_timeout = set_int(:soft_timeout, seconds, 3)
cleanup_timeout = set_int(:cleanup_timeout, cleanup, 2)
set_int(:timeout, soft_timeout + cleanup_timeout, 5)
+ end
+
+ def timeout_signal(*args, &block)
+ if block_given?
+ set_hook(:timeout_signal, block, 1)
+ elsif args.first.respond_to?(:call)
+ set_hook(:timeout_signal, args.first, 1)
+ elsif args.first.is_a?(Symbol)
+ signal = args.first
+ set_hook(:timeout_signal, ->(_pid) { signal }, 1)
+ else
+ raise ArgumentError, "timeout_signal must be a symbol or a proc"
+ end
end
def spawn_timeout(seconds)
set_int(:spawn_timeout, seconds, 1)
end