views:

34

answers:

2

I'm trying to plan how to build some functionality into my new app, and am unsure if there is a "correct" way to achieve what I am looking for.

There are certain things that I want to get done with my site, say when a certain dateTime is matched aginst some other date time, then send email.

Or for example, consider the badges on stackoverflow, do you think it is done with some big loop testing for people qualifing for new badges, or is there some design pattern I am missing.

This is my current plan.

  1. Setup a function, that will be triggered every 1-10 mins, which will check the db for any rules being met, and therefore action to be taken.

  2. Add these checks on a per user basis, when a user looks at any records related to them, or logs in.

If anyone could shed any light on how for example ebay would handle it's email notifications, I think that would point me in the right direction.

Thanks for any help. Even the name of what I am looking for would be greatly helpful.

+1  A: 

What you're doing is, indeed, usually done outside the "web app". You can call it a "batch job", or a "scheduled task", or whatever you like. The way it's usually done, at least on unix-like systems, is by using cron. Cron uses a simple configuration file to say, for example, "every ten minutes, run the shell script that cleans the user database", or, "At midnight, vacuum the database". If you're using a Windows server, then I don't know how it's usually done there.

Jonathan Feinberg
yep, sounds good to me, I've used crons before. What I'm wondering though is there a better way to do it, that wouldn't mean running the batch job all the time. For email notifications etc, I want them to be sent as soon as possible, but hopefully not with running the whole batch every minute.
optician
Yes, indeed. That's usually done through the use of message queues.
Jonathan Feinberg
I'm thinking of having a job queue as well, so the app dosent have to get tied up while doing things, or could send mail in an orderly fashion.
optician
A: 

There is probably a lib available for this. If you are using Java Quartz might be for you: http://www.opensymphony.com/quartz/

I'd hope something similar is available for other mainstream languages.

Jens Schauder