lib/slowpoke/railtie.rb in slowpoke-0.2.1 vs lib/slowpoke/railtie.rb in slowpoke-0.3.0
- old
+ new
@@ -1,13 +1,16 @@
module Slowpoke
class Railtie < Rails::Railtie
+ config.slowpoke = ActiveSupport::OrderedOptions.new
+
initializer "slowpoke" do |app|
- Rack::Timeout.service_timeout = Slowpoke.timeout
- if Rails::VERSION::MAJOR >= 5
- app.config.middleware.insert_after ActionDispatch::DebugExceptions, Rack::Timeout
- else
- app.config.middleware.insert_before ActionDispatch::RemoteIp, Rack::Timeout
- end
+ service_timeout = app.config.slowpoke.timeout
+ service_timeout ||= ENV["RACK_TIMEOUT_SERVICE_TIMEOUT"] || ENV["REQUEST_TIMEOUT"] || ENV["TIMEOUT"] || 15
+ service_timeout = service_timeout.to_i
+
+ app.config.middleware.insert_after ActionDispatch::DebugExceptions, Rack::Timeout,
+ service_timeout: service_timeout
+
app.config.middleware.insert(0, Slowpoke::Middleware) unless Rails.env.development? || Rails.env.test?
end
end
end