-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrailtie.rb
More file actions
26 lines (22 loc) · 980 Bytes
/
Copy pathrailtie.rb
File metadata and controls
26 lines (22 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Slowpoke
class Railtie < Rails::Railtie
config.slowpoke = ActiveSupport::OrderedOptions.new
# must happen outside initializer (so it runs earlier)
config.action_dispatch.rescue_responses.merge!(
"Rack::Timeout::RequestTimeoutError" => :service_unavailable,
"Rack::Timeout::RequestExpiryError" => :service_unavailable
)
initializer "slowpoke" do |app|
service_timeout = app.config.slowpoke.timeout
service_timeout ||= ENV["RACK_TIMEOUT_SERVICE_TIMEOUT"] || ENV["REQUEST_TIMEOUT"] || ENV["TIMEOUT"] || 15
if service_timeout.respond_to?(:call)
app.config.middleware.insert_after ActionDispatch::DebugExceptions, Slowpoke::Timeout,
service_timeout: service_timeout
else
app.config.middleware.insert_after ActionDispatch::DebugExceptions, Rack::Timeout,
service_timeout: service_timeout.to_i
end
app.config.middleware.insert(0, Slowpoke::Middleware)
end
end
end