lib/picky/rack/harakiri.rb in picky-2.7.0 vs lib/picky/rack/harakiri.rb in picky-3.0.0.pre1
- old
+ new
@@ -1,55 +1,59 @@
-module Rack # :nodoc:
-
- # Simple Rack Middleware to kill Unicorns after X requests.
- #
- # Use as follows in e.g. your rackup File:
- #
- # Rack::Harakiri.after = 100
- # use Rack::Harakiri
- #
- # Then the Unicorn will commit suicide after 100 requests (50 is the default).
- #
- # The Master Unicorn process forks a new child Unicorn to replace the old one.
- #
- class Harakiri
-
- # Set the amount of requests before the Unicorn commits Harakiri.
+module Picky
+
+ module Rack # :nodoc:
+
+ # Simple Rack Middleware to kill Unicorns after X requests.
#
- cattr_accessor :after
-
- def initialize app
- @app = app
-
- @requests = 0
- @quit_after_requests = self.class.after || 50
- end
-
- # #call interface method.
+ # Use as follows in e.g. your rackup File:
#
- # Harakiri is a middleware, so it delegates the the app or
- # the next middleware after checking if it is time to honorably retire.
+ # Rack::Harakiri.after = 100
+ # use Rack::Harakiri
#
- def call env
- harakiri
- @app.call env
- end
-
- # Checks to see if it is time to honorably retire.
+ # Then the Unicorn will commit suicide after 100 requests (50 is the default).
#
- # If yes, kills itself (Unicorn will answer the request, honorably).
+ # The Master Unicorn process forks a new child Unicorn to replace the old one.
#
- # Note: Sends its process a QUIT signal if it is time.
- #
- def harakiri
- @requests = @requests + 1
- Process.kill(:QUIT, Process.pid) if harakiri?
+ class Harakiri
+
+ # Set the amount of requests before the Unicorn commits Harakiri.
+ #
+ cattr_accessor :after
+
+ def initialize app
+ @app = app
+
+ @requests = 0
+ @quit_after_requests = self.class.after || 50
+ end
+
+ # #call interface method.
+ #
+ # Harakiri is a middleware, so it delegates the the app or
+ # the next middleware after checking if it is time to honorably retire.
+ #
+ def call env
+ harakiri
+ @app.call env
+ end
+
+ # 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.
+ #
+ def harakiri
+ @requests = @requests + 1
+ Process.kill(:QUIT, Process.pid) if harakiri?
+ end
+
+ # Is it time to honorably retire?
+ #
+ def harakiri?
+ @requests >= @quit_after_requests
+ end
+
end
-
- # Is it time to honorably retire?
- #
- def harakiri?
- @requests >= @quit_after_requests
- end
-
end
+
end
\ No newline at end of file