Class: Rack::Harakiri
Overview
Class Attribute Summary collapse
-
.after ⇒ Object
Returns the value of attribute after.
Instance Method Summary collapse
-
#call(env) ⇒ Object
#call interface method.
-
#harakiri ⇒ Object
Checks to see if it is time to honorably retire.
-
#harakiri? ⇒ Boolean
Is it time to honorably retire?.
-
#initialize(app) ⇒ Harakiri
constructor
A new instance of Harakiri.
Constructor Details
#initialize(app) ⇒ Harakiri
Returns a new instance of Harakiri.
22 23 24 25 26 27 |
# File 'lib/picky/rack/harakiri.rb', line 22 def initialize app @app = app @requests = 0 @quit_after_requests = self.class.after || 50 end |
Class Attribute Details
.after ⇒ Object
Returns the value of attribute after.
19 20 21 |
# File 'lib/picky/rack/harakiri.rb', line 19 def after @after end |
Instance Method Details
#call(env) ⇒ Object
#call interface method.
Harakiri is a middleware, so it forwards the the app or the next middleware after checking if it is time to honorably retire.
34 35 36 37 |
# File 'lib/picky/rack/harakiri.rb', line 34 def call env harakiri @app.call env end |
#harakiri ⇒ Object
Checks to see if it is time to honorably retire.
If yes, kills itself (Unicorn will answer the request, honorably).
Note: Sends its process a QUIT signal if it is time.
45 46 47 48 |
# File 'lib/picky/rack/harakiri.rb', line 45 def harakiri @requests = @requests + 1 Process.kill(:QUIT, Process.pid) if harakiri? end |
#harakiri? ⇒ Boolean
Is it time to honorably retire?
52 53 54 |
# File 'lib/picky/rack/harakiri.rb', line 52 def harakiri? @requests >= @quit_after_requests end |