views:

79

answers:

2

I would like to do a cron job every 10 minutes, but my system only does 1 hour. So I'm looking for a method to do this. I've seen Timer and sleep but I'm not sure how to do this or even better yet a resource for achieving this.

+2  A: 

To do this reliably, invest in a VPS and create the 10-minute cron job as desired. Trying to emulate cron all on your own is very likely to fail in unforeseen ways.

Creating a sleeping process is not the way to go about this; if your server doesn't give you the freedom to make your own cron as you like it, you probably can't create your own background process for this sort of thing, either. You might be able to, on each request, take a look and see how many of the jobs need done (if it was 25 minutes since last request, you might have to do two), and go back and do them retroactively.

But, seriously. You need your own server to do this dependably.

Matchu
no reason to reimplement the wheel, especially considering how widely used, robust, and mature cron is. +1
Matt Briggs
+1  A: 

Take a look at http://rufus.rubyforge.org/rufus-scheduler/

rufus-scheduler is a Ruby gem for scheduling pieces of code (jobs). It understands running a job AT a certain time, IN a certain time, EVERY x time or simply via a CRON statement. rufus-scheduler is no replacement for cron/at since it runs inside of Ruby.

grm
looks like it could work. I will get back on this.
Sam
I haven't used it myself, but I took some ideas from it while creating a job scheduler with node.js. The code looks good and I think it would work for you. Also: http://adam.heroku.com/past/2010/4/13/rethinking_cron/
grm
I see that this article also mention: http://github.com/bvandenbos/resque-scheduler
grm
Also: http://github.com/adamwiggins/clockwork :)
grm