I use rack-timeout and it works fine. But I couldn't figure out how to set time for a particular URL.
Even if I do like:
map '/foo/bar' do Rack::Timeout.timeout = 10 end
not only /foo/bar action but every action dies after 10 second.
Is it possible to set timeout for a particular URL? Or should I use another solution other than rack-timeout?
If you're worried about particular actions running too long, I would wrap the code of concern in a Timeout block instead of trying to enforce timeouts on a URL level. You could easily wrap up the below into a helper method and use it with a variable timeout throughout your controllers.
require "timeout'"
begin
status = Timeout::timeout(10) {
# Potentially long process here...
}
rescue Timeout::Error
puts 'This is taking way too long.'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With