Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular delayed jobs

I'm using Delayed Job to manage background work.
However I have some tasks that need to be executed at regular interval. Every hour, every day or every week for example.

For now, when I execute the task, I create a new one to be executed in one day/week/month.

However I don't really like it. If for any reason, the task isn't completely executed, we don't create the next one and we might lose the execution of the task.

How do you manage that kind of things (with delayed job) in your rails apps to be sure your regular tasks list remains correct ?

like image 653
Damien MATHIEU Avatar asked Oct 28 '09 10:10

Damien MATHIEU


2 Answers

If you have access to Cron, I highly recommend Whenever

http://github.com/javan/whenever

You specify what you want to run and at what frequency in dead simple ruby, and whenever supplies rake tasks to convert this into a crontab and to update your system's crontab.

If you don't have access to frequent cron (like I don't, since we're on Heroku), then DJ is the way to go.

You have a couple options.

  1. Do what you're doing. DJ will retry each task a certain number of times, so you have some leniency there

  2. Put the code that creates the next DJ job in an ensure block, to make sure it gets created even after an exception or other bad event

  3. Create another DJ that runs periodically, checks to make sure the appropriate DJs exist, and creates them if they don't. Of course, this is just as error prone as the other options, since the monitor and the actual DJ are both running in the same env, but it's something.

like image 101
Mike H Avatar answered Oct 17 '22 01:10

Mike H


Is there any particular reason why you wouldn't use cron for this type of things? Or maybe something more rubyish like rufus-scheduler, which is quite easy to use and very reliable.

If you don't need queuing, these tools are a way to go, I think.

like image 31
Milan Novota Avatar answered Oct 17 '22 00:10

Milan Novota