Class: Slowpoke::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



3
4
5
# File 'lib/slowpoke/middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/slowpoke/middleware.rb', line 7

def call(env)
  @app.call(env)
ensure
  if env[Slowpoke::ENV_KEY]
    # extremely important
    # protect the process with a restart
    # https://github.com/heroku/rack-timeout/issues/39
    # can't do in timed_out state consistently
    if defined?(::PhusionPassenger)
      `passenger-config detach-process #{Process.pid}`
    else
      Process.kill("QUIT", Process.pid)
    end
  end
end