开发者

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 开发者_如何学Gothat periodically requests an action on my Heroku app. This action will in turn run some processing that may take 1 or 2 minutes to complete. I believe Heroku has 30 second request limit, I was thinking could call a Rake task from my controller action instead.

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. In fact, if the task is forked from a HTTP Request, the timeout will be the same of the HTTP request.

You should a different method to start the task. Either a crontab (on Heroku side) or a Worker as good solutions.


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 e.g.

rake delay:db:seed

which will execute

rake db:seed

as a 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜