lib/picky/rack/harakiri.rb in picky-0.12.3 vs lib/picky/rack/harakiri.rb in picky-1.0.0
- old
+ new
@@ -1,6 +1,6 @@
-module Rack
+module Rack # :nodoc:
# Simple Rack Middleware to kill Unicorns after X requests.
#
# Use as follows in e.g. your rackup File:
#
@@ -14,33 +14,42 @@
class Harakiri
# Set the amount of requests before the Unicorn commits Harakiri.
#
cattr_accessor :after
- attr_reader :quit_after_requests
def initialize app
@app = app
@requests = 0
@quit_after_requests = self.class.after || 50
end
- # Harakiri is a middleware, so it passes the call on after checking if it
- # is time to honorably retire.
+ # #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 @requests >= @quit_after_requests
+ Process.kill(:QUIT, Process.pid) if harakiri?
+ end
+
+ # Is it time to honorably retire?
+ #
+ def harakiri?
+ @requests >= @quit_after_requests
end
end
end
\ No newline at end of file