notification scheduling question
Posted
by sims
on Stack Overflow
See other posts from Stack Overflow
or by sims
Published on 2010-04-18T12:43:28Z
Indexed on
2010/04/18
12:53 UTC
Read the original article
Hit count: 406
Hi Stackers!
I'm building an app that needs to send out notifications to users depending on user definable "notifications". So the notifications are not per event. They are arbitrary. A cron job should query the database and send out emails when it finds an event with matching criterion.
The is a scheduling app. So naturally, one of the criterion is time. I think I've figured it out, but I'm sure there are better ideas out there as it seems to be a fairly common thing to do.
I think I'll limit the users ability to "minutes before hand" to get notified as opposed to seconds or hours.
So I have an eventA and notificationA. notificationA should be triggered if an event is due within 45 minutes. So eventA starts at 17:30. The user should be notified at 16:45. But the cron job might not run exactly at 00 seconds. So when the difference is not 45 minutes and 0 seconds it is, say, 45 minutes and 5 seconds. Notification time is past. Email doesn't get sent. User misses event. Shugar.
We should also take into account that the cron job might take a long time to run. So maybe we should only trigger it every 5 minutes. So we need a bigger interval maybe.
So then my guess would be to say that:
if ((eventDueTime - now > notificationTimeValue - interval) && (eventDueTime - now < notificationTimeValue + interval)) sendTheFrikinNotificationAlready();
It seems kind of risky if the there are thousands of notifications to send out. I guess I could make a thread for each notification and then a thread for each event that matches the criterion. That might help.
Does that make sense? Any other ideas? Thanks!
© Stack Overflow or respective owner