Class: WorkerKiller::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/worker_killer/middleware.rb

Direct Known Subclasses

OOMLimiter, RequestsLimiter

Defined Under Namespace

Classes: OOMLimiter, RequestsLimiter

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#killerObject (readonly)

Returns the value of attribute killer.



7
8
9
# File 'lib/worker_killer/middleware.rb', line 7

def killer
  @killer
end

#limiterObject (readonly)

Returns the value of attribute limiter.



7
8
9
# File 'lib/worker_killer/middleware.rb', line 7

def limiter
  @limiter
end

#reactionObject (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