4

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

3 Answers 3

4

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.

2

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.

6
  • Thanks. But I should have added that I'd like to avoid a background worker. I only need to do this periodically and adding a workers would be a bit costly for this. I was hoping a rake task would do the trick.
    – Jim Jones
    Feb 22, 2010 at 13:21
  • You can dynamically control the number of workers you have, you can fire one up just for the duration required to execute your task.
    – jonnii
    Feb 22, 2010 at 16:22
  • Can i execute a worker via an HTTP request that calls a rake task?
    – Jim Jones
    Feb 24, 2010 at 18:20
  • You'd most likely make a web request to a restful service which would register a new delayed_job. This would get picked up by the worker immediately.
    – jonnii
    Feb 24, 2010 at 18:23
  • thanks this is very helpful. so, i could have a controller action that uses the heroku client lib to create a worker upon request. but, how could i tear the worker down after the job completed?
    – Jim Jones
    Feb 24, 2010 at 18:35
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.