简体   繁体   English

Heroku上的Rake任务可以超时吗?

[英]Can a Rake task on Heroku time out?

I'm using Heroku and would like to have a script (on another server) called via cron that periodically requests an action on my Heroku app. 我正在使用Heroku,并希望通过cron调用一个脚本(在另一台服务器上),该脚本定期在我的Heroku应用程序上请求操作。 This action will in turn run some processing that may take 1 or 2 minutes to complete. 此操作将依次运行一些可能需要1或2分钟才能完成的处理。 I believe Heroku has 30 second request limit, I was thinking could call a Rake task from my controller action instead. 我相信Heroku有30秒的请求限制,我认为可以从我的控制器操作调用Rake任务。

Would this work? 这会有用吗? I'm curious if anyone has tried this yet. 我很好奇是否还有人试过这个。

Thanks. 谢谢。

The rake task would work as long as you don't use a HTTP request as proxy to initiate the task. 只要您不使用HTTP请求作为代理来启动任务,rake任务就会起作用。 In fact, if the task is forked from a HTTP Request, the timeout will be the same of the HTTP request. 实际上,如果任务是从HTTP请求分叉的,则超时将与HTTP请求相同。

You should a different method to start the task. 您应该使用不同的方法来启动任务。 Either a crontab (on Heroku side) or a Worker as good solutions. 无论是crontab(在Heroku方面)还是工作者都是很好的解决方案。

I'd recommend using a background job on a worker for this. 为了这个,我建议在工人身上使用后台工作。 Your periodic process would then just have to start the worker and it wouldn't matter how long the process took. 然后,您的定期流程只需要启动工作人员,这个过程需要多长时间。

I've just created a gem to solve exactly this problem. 我刚刚创建了一个宝石来解决这个问题。 It allows you to queue up any rake task as a delayed_job eg 它允许您将任何rake任务排队为delayed_job,例如

rake delay:db:seed

which will execute 哪个会执行

rake db:seed

as a delayed_job. 作为delayed_job。 You can find it at http://rubygems.org/gems/delayed_task or http://blog.opsb.co.uk/long-running-rake-tasks-on-heroku . 您可以在http://rubygems.org/gems/delayed_taskhttp://blog.opsb.co.uk/long-running-rake-tasks-on-heroku找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM