views:

40

answers:

3

Guys,

Is there a way to setup a callback in ROR that would trigger at a specific time?

Lets say I'm running a contest that expries at a certain time. Lets say Monday July 28th at 9:00. I'd like to set up an observer that ran a function at Monday July 28th at 9:00. Does rails have a method to do this?

A: 

You'd be better off writing a ruby script that runs via crontab at the exact time you need it to.

Eimantas
A: 

I agree about crontab, but I like whenever. It has a nice integration into cron that you can store with your repo and it integrates nicely with capistrano.

Geoff Lanotte
+1  A: 

There's a run_at field in Delayed Job. You have to have a worker process in the background always running and looking for jobs that a set to run, but if your application is doing this a lot, it might be easier than always writing new cron jobs.

So, you could have a method in your Contest model that gets called in a after_create callback that sets up a delayed job to send out an email to a random winner at the date that's specified.

If it's a one time, or very infrequent deal, though, I'll agree about using whenever

Dan McNevin
This will happen quite a bit, so I think Delayed Job might be best, thank you.
TheDelChop