I'm having working on a Rails application that is supposed to run on an Nginx server. Depending on the input, the application may take very long to process the requests (or hang up in case of bugs), so I want to prevent processes from running forever. Apart from the Nginx configuration, which ensures that the client gets a timeout signal, I think I still may have to make sure that my app stops working on those requests. Where should this be handled? Within my Rails app (using Timeout/Thread from std-lib) or externally (killing processes)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I usually do this at the Rack layer using Rack::Timeout.
# config/initializers/timeout.rb
Rack::Timeout.timeout = 10 # seconds