-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
! specs, + Picky::Rack::Harakiri -> Rack::Harakiri
- Loading branch information
Showing
8 changed files
with
100 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Picky | ||
|
||
module Backends | ||
|
||
module Internal | ||
|
||
# Nothing needs to be deleted from it. | ||
# | ||
def delete _ | ||
|
||
end | ||
|
||
# It does not need to be cleared. | ||
# | ||
def clear | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,58 @@ | ||
module Picky | ||
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. | ||
# | ||
class << self | ||
attr_accessor :after | ||
end | ||
|
||
module Rack # :nodoc: | ||
def initialize app | ||
@app = app | ||
|
||
# Simple Rack Middleware to kill Unicorns after X requests. | ||
@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. | ||
# | ||
class Harakiri | ||
|
||
# Set the amount of requests before the Unicorn commits Harakiri. | ||
# | ||
class << self | ||
attr_accessor :after | ||
end | ||
|
||
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 | ||
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 | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters