views:

347

answers:

2

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.

+1  A: 

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.

jonnii
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
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
Can i execute a worker via an HTTP request that calls a rake task?
Jim Jones
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
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
At the end of your task start a new delayed_job task to bring the worker down. I haven't tried this, so I'm not sure if it'd work, but it'd be worth a try. Have you also looked at using a cron task?
jonnii
+1  A: 

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.

Simone Carletti