下载文件时,heroku unicorn超时不起作用

时间:2014-04-29 13:51:46

标签: ruby-on-rails heroku timeout xls unicorn

我正在使用Unicorn在Heroku上运行rails 4应用程序。

此应用会创建一个相当大的xls文件

为了给它足够的时间,我通过config / unicorn.rb增加了超时:

超时240

当我运行生成xls文件的页面时,这不起作用,在3001ms之后发生超时。

为什么?

这是我的日志:

2014-04-29T13:43:27.323190+00:00 app[web.1]: I, [2014-04-29T13:43:27.323084 #8]  INFO -- : Started GET "/live_sales.xls?action=index&controller=live_sales" for 81.244.45.218 at 2014-04-29 13:43:27 +0000
2014-04-29T13:43:27.340252+00:00 app[web.1]: D, [2014-04-29T13:43:27.340190 #8] DEBUG -- : logged in? true
2014-04-29T13:43:27.339294+00:00 app[web.1]: I, [2014-04-29T13:43:27.339181 #8]  INFO -- : Processing by LiveSalesController#index as XLS
2014-04-29T13:43:27.345465+00:00 app[web.1]: D, [2014-04-29T13:43:27.345383 #8] DEBUG -- :   ItemRef Load (3.1ms)  SELECT gamme FROM "item_refs" WHERE (gamme is not null and gamme <> '') GROUP BY gamme
2014-04-29T13:43:28.577687+00:00 app[web.1]: D, [2014-04-29T13:43:28.577526 #8] DEBUG -- :   LiveSale Load (1210.0ms)  SELECT invoice_date, item_refs.item_brand, item_refs.item_label, item_refs.gamme, item_refs.sub_gamme, item_refs.id, item_refs.item_reference, item_refs.date_published, item_refs.date_unpublished, item_refs.price_purchase, item_refs.current_stock, item_refs.item_published,
2014-04-29T13:43:28.577694+00:00 app[web.1]:  sum(price_purchase * current_stock) as stock_value,sum(quantity) as quantity,
2014-04-29T13:43:28.577697+00:00 app[web.1]:  sum(price_purchase * quantity) as total_purchase FROM "live_sales" left join item_refs on item_refs.id = live_sales.item_ref_id and item_refs.item_published is true and item_refs.disabled is false WHERE ((invoice_date between '2014-03-29 13:43:27 +0000' and '2014-04-29 13:43:27 +0000')) GROUP BY invoice_date, item_refs.item_brand, item_refs.item_label, item_refs.gamme, item_refs.sub_gamme, item_refs.id, item_refs.item_reference, item_refs.date_published, item_refs.date_unpublished, item_refs.price_purchase, item_refs.current_stock, item_refs.item_published ORDER BY invoice_date asc, 
2014-04-29T13:43:57.331088+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path=/live_sales.xls?action=index&controller=live_sales host=azzanalytics.herokuapp.com request_id=6e67b74e-3db8-4853-b5c6-c1f884eaa31e fwd="81.244.45.218" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0

谢谢!

1 个答案:

答案 0 :(得分:0)

建议是:使用后台进程!

没有办法绕过它! Web应用程序中的最佳实践是尽快返回客户端,因为它释放了资源。当你只有一个dyno在heroku运行并且你有多个请求时,它们将被阻止超时,并且没有用户能够访问你的页面。当您拥有这样的长期流程时,您可以轻松地拒绝服务案例。 heroku在30秒内超时,无论你在瘦服务器上覆盖它

如果您因成本问题而不想执行后台处理,请查看免费增值:https://github.com/phoet/freemiumdelayed_job