Class: RailsFCGIHandler
Constant Summary collapse
- SIGNALS =
{ 'HUP' => :reload, 'INT' => :exit_now, 'TERM' => :exit_now, 'USR1' => :exit, 'USR2' => :restart }
- GLOBAL_SIGNALS =
SIGNALS.keys - %w(USR1)
Instance Attribute Summary collapse
-
#gc_request_period ⇒ Object
Returns the value of attribute gc_request_period.
-
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
-
#when_ready ⇒ Object
readonly
Returns the value of attribute when_ready.
Class Method Summary collapse
-
.process!(*args, &block) ⇒ Object
Initialize and run the FastCGI instance, passing arguments through to new.
Instance Method Summary collapse
-
#initialize(log_file_path = nil, gc_request_period = nil) {|_self| ... } ⇒ RailsFCGIHandler
constructor
Initialize the FastCGI instance with the path to a crash log detailing unhandled exceptions (default RAILS_ROOT/log/fastcgi.crash.log) and the number of requests to process between garbage collection runs (default nil for normal GC behavior.) Optionally, pass a block which takes this instance as an argument for further configuration.
- #process!(provider = FCGI) ⇒ Object
Constructor Details
#initialize(log_file_path = nil, gc_request_period = nil) {|_self| ... } ⇒ RailsFCGIHandler
Initialize the FastCGI instance with the path to a crash log detailing unhandled exceptions (default RAILS_ROOT/log/fastcgi.crash.log) and the number of requests to process between garbage collection runs (default nil for normal GC behavior.) Optionally, pass a block which takes this instance as an argument for further configuration.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fcgi_handler.rb', line 31 def initialize(log_file_path = nil, gc_request_period = nil) self.log_file_path = log_file_path || "#{RAILS_ROOT}/log/fastcgi.crash.log" self.gc_request_period = gc_request_period # Yield for additional configuration. yield self if block_given? # Safely install signal handlers. install_signal_handlers @app = Dispatcher.new # Start error timestamp at 11 seconds ago. @last_error_on = Time.now - 11 end |
Instance Attribute Details
#gc_request_period ⇒ Object
Returns the value of attribute gc_request_period.
19 20 21 |
# File 'lib/fcgi_handler.rb', line 19 def gc_request_period @gc_request_period end |
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
18 19 20 |
# File 'lib/fcgi_handler.rb', line 18 def log_file_path @log_file_path end |
#when_ready ⇒ Object (readonly)
Returns the value of attribute when_ready.
16 17 18 |
# File 'lib/fcgi_handler.rb', line 16 def when_ready @when_ready end |
Class Method Details
.process!(*args, &block) ⇒ Object
Initialize and run the FastCGI instance, passing arguments through to new.
22 23 24 |
# File 'lib/fcgi_handler.rb', line 22 def self.process!(*args, &block) new(*args, &block).process! end |
Instance Method Details
#process!(provider = FCGI) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fcgi_handler.rb', line 47 def process!(provider = FCGI) mark_features! dispatcher_log :info, 'starting' process_each_request provider dispatcher_log :info, 'stopping gracefully' rescue Exception => error case error when SystemExit dispatcher_log :info, 'stopping after explicit exit' when SignalException dispatcher_error error, 'stopping after unhandled signal' else # Retry if exceptions occur more than 10 seconds apart. if Time.now - @last_error_on > 10 @last_error_on = Time.now dispatcher_error error, 'retrying after unhandled exception' retry else dispatcher_error error, 'stopping after unhandled exception within 10 seconds of the last' end end end |