Class: WorkerKiller::Middleware
- Inherits:
-
Object
- Object
- WorkerKiller::Middleware
- Defined in:
- lib/worker_killer/middleware.rb
Direct Known Subclasses
Defined Under Namespace
Classes: OOMLimiter, RequestsLimiter
Instance Attribute Summary collapse
-
#killer ⇒ Object
readonly
Returns the value of attribute killer.
-
#limiter ⇒ Object
readonly
Returns the value of attribute limiter.
-
#reaction ⇒ Object
readonly
Returns the value of attribute reaction.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, killer:, klass:, reaction: nil, **opts) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, killer:, klass:, reaction: nil, **opts) ⇒ Middleware
Returns a new instance of Middleware.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/worker_killer/middleware.rb', line 9 def initialize(app, killer:, klass:, reaction: nil, **opts) @app = app @killer = killer @reaction = reaction || proc do |l, k| k.kill(l.started_at) end @limiter = klass.new(**opts) end |
Instance Attribute Details
#killer ⇒ Object (readonly)
Returns the value of attribute killer.
7 8 9 |
# File 'lib/worker_killer/middleware.rb', line 7 def killer @killer end |
#limiter ⇒ Object (readonly)
Returns the value of attribute limiter.
7 8 9 |
# File 'lib/worker_killer/middleware.rb', line 7 def limiter @limiter end |
#reaction ⇒ Object (readonly)
Returns the value of attribute reaction.
7 8 9 |
# File 'lib/worker_killer/middleware.rb', line 7 def reaction @reaction end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 |
# File 'lib/worker_killer/middleware.rb', line 20 def call(env) @app.call(env) ensure reaction.call(limiter, killer) if limiter.check end |