lib/pitchfork/configurator.rb in pitchfork-0.1.2 vs lib/pitchfork/configurator.rb in pitchfork-0.2.0

- old
+ new

@@ -29,34 +29,33 @@ DEFAULTS = { :timeout => 20, :logger => Logger.new($stderr), :worker_processes => 1, :after_fork => lambda { |server, worker| - server.logger.info("worker=#{worker.nr} gen=#{worker.generation} pid=#{$$} spawned") - }, - :before_fork => lambda { |server, worker| - server.logger.info("worker=#{worker.nr} gen=#{worker.generation} spawning...") - }, + server.logger.info("worker=#{worker.nr} gen=#{worker.generation} pid=#{$$} spawned") + }, + :after_promotion => lambda { |server, worker| + server.logger.info("gen=#{worker.generation} pid=#{$$} promoted") + }, :after_worker_exit => lambda { |server, worker, status| - m = if worker.nil? - "repead unknown process (#{status.inspect})" - elsif worker.mold? - "mold pid=#{worker.pid rescue 'unknown'} gen=#{worker.generation rescue 'unknown'} reaped (#{status.inspect})" - else - "worker=#{worker.nr rescue 'unknown'} pid=#{worker.pid rescue 'unknown'} gen=#{worker.generation rescue 'unknown'} reaped (#{status.inspect})" - end - if status.success? - server.logger.info(m) - else - server.logger.error(m) - end - }, + m = if worker.nil? + "repead unknown process (#{status.inspect})" + elsif worker.mold? + "mold pid=#{worker.pid rescue 'unknown'} gen=#{worker.generation rescue 'unknown'} reaped (#{status.inspect})" + else + "worker=#{worker.nr rescue 'unknown'} pid=#{worker.pid rescue 'unknown'} gen=#{worker.generation rescue 'unknown'} reaped (#{status.inspect})" + end + if status.success? + server.logger.info(m) + else + server.logger.error(m) + end + }, :after_worker_ready => lambda { |server, worker| - server.logger.info("worker=#{worker.nr} ready") - }, + server.logger.info("worker=#{worker.nr} gen=#{worker.generation} ready") + }, :early_hints => false, - :mold_selector => MoldSelector::LeastSharedMemory.new, :refork_condition => nil, :check_client_connection => false, :rewindable_input => true, :client_body_buffer_size => Pitchfork::Const::MAX_BODY, } @@ -83,13 +82,10 @@ parse_rackup_file RACKUP[:set_listener] and set[:listeners] << "#{RACKUP[:host]}:#{RACKUP[:port]}" - - RACKUP[:no_default_middleware] and - set[:default_middleware] = false end def commit!(server, options = {}) #:nodoc: skip = options[:skip] || [] if ready_pipe = RACKUP.delete(:ready_pipe) @@ -121,30 +117,26 @@ end set[:logger] = obj end - def before_fork(*args, &block) - set_hook(:before_fork, block_given? ? block : args[0]) - end - def after_fork(*args, &block) set_hook(:after_fork, block_given? ? block : args[0]) end + def after_promotion(*args, &block) + set_hook(:after_promotion, block_given? ? block : args[0]) + end + def after_worker_ready(*args, &block) set_hook(:after_worker_ready, block_given? ? block : args[0]) end def after_worker_exit(*args, &block) set_hook(:after_worker_exit, block_given? ? block : args[0], 3) end - def mold_selector(*args, &block) - set_hook(:mold_selector, block_given? ? block : args[0], 3) - end - def timeout(seconds) set_int(:timeout, seconds, 3) # POSIX says 31 days is the smallest allowed maximum timeout for select() max = 30 * 60 * 60 * 24 set[:timeout] = seconds > max ? max : seconds @@ -152,14 +144,10 @@ def worker_processes(nr) set_int(:worker_processes, nr, 1) end - def default_middleware(bool) - set_bool(:default_middleware, bool) - end - def early_hints(bool) set_bool(:early_hints, bool) end # sets listeners to the given +addresses+, replacing or augmenting the @@ -206,11 +194,15 @@ end # Defines the number of requests per-worker after which a new generation # should be spawned. # + # +false+ can be used to mark a final generation, otherwise the last request + # count is re-used indefinitely. + # # example: #. refork_after [50, 100, 1000] + #. refork_after [50, 100, 1000, false] # # Note that reforking is only available on Linux. Other Unix-like systems # don't have this capability. def refork_after(limits) set[:refork_condition] = ReforkCondition::RequestsCount.new(limits)