views:

21

answers:

2

Hi folks, i would like to trigger an event sometime in the future based on an event that is currently happening. I do not expect the volume to be too high, so i care a lot more about simplicity than performance.

For example:

  • event A happens. i need event B to happen a day later (not time critical)
  • system stores a record of event in db
  • ongoing process looks through the db, and executes the event Bs that are ready, and removes them from db

Does this make sense? I am using Ruby on rails - I imagine this is a fairly common usecase

+1  A: 

Yes it absolutely makes sense :). You should be probably looking at a Scheduler or a process that runs in the background. Take a look here and here

Basically, whenever you finish executing your event A, you will be putting an entry in the database with a field indicating when it should run. As you say, your ongoing process which should be scheduled to run in the background can either be scheduled in steps or do a polling and query the DB and carry on from there like you've said.

Bragboy
+2  A: 

Use the DelayedJob gem. Refer to this screen-cast for more details.

KandadaBoggu