我正在使用heroku托管一个支持iOS应用程序的ruby on rails应用程序。我有一个可能会持续很长时间的请求,我需要能够在我的请求被终止之前捕捉到超时。我使用Timeout::timeout(15)抛出一个错误并进行适当的处理。这在我的本地运行得很好,我可以看到抛出并记录了错误。当我在heroku上运行相同的代码时,没有记录错误。我在尝试使用机架超时gem时也遇到了同样的问题。
还有没有人在Heroku上超时运行时遇到问题?我在雪松上。
发布于 2013-08-07 13:21:56
# app/controllers/index_controller.rb
require 'timeout'
Class IndexController < ApplicationController
def timeout
begin
status = Timeout::timeout(5) {
sleep(6)
render :text => "will never be rendered"
rescue Timeout::Error
render :text => "timeout handled"
end
end
end
end
# config/routes.rb
match '/timeout' => "index#timeout"这在heroku上运行良好:http://young-gorge-7585.herokuapp.com
发布于 2013-08-13 02:38:32
看看如何使用Rack::Timeout,它就是为这个目的而设计的。
https://stackoverflow.com/questions/16818741
复制相似问题