Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with very long running rake task

I am interested in running a very long running rake task, one that would take hours to complete and I am interested in learning about best practices for dealing with this problem.

Possible solutions I have found:

  1. Set up a cron job
  2. delayed_job
  3. resque

cron seems like a simple solution to set up, but is it ideal for a very long task? What do you use and what are the advantages/disadvantages of your solution?

like image 871
JZ. Avatar asked Mar 26 '12 17:03

JZ.


1 Answers

Personally I love Resque, you can use the resque-scheduler gem for dealing with long running or periodic tasks.

If you don't have to run your task very often, you can demonize the the rake task to make sure it keeps running if your SSH session dies or something.

Try something like this:

nohup rake my:task &

nohup will send the output to nohup.out in the directory you run the task in, and will also let leave your ssh session without the process dying, secondly the & will run it as a deamon.

like image 89
JP Silvashy Avatar answered Sep 22 '22 05:09

JP Silvashy