I have a db of "event" (a conference, birthday party etc.) records, and each event has an endTime
field. After an event ends, I'd like to send out 2-3 emails for each past event.
Right now, I run an hourly cron job to find all events that has ended in the past hour, so it looks something like:
- at 2:01pm: find all events ending between 1-2pm, send emails
- at 3:01pm: find all events ending between 2-3pm, send emails
- at 4:01pm: find all events ending between 3-4pm, send emails
- at 5:01pm: ...
However, say when the 3:01pm job fails for some reason (Heroku crashes my rest api, email service provider goes down etc.), the events ending between 2-3pm won't get emails.
At the moment, my db records are not marked as notified
if the emails were sent successfully. Should I do that so I can change the cron script to "find all records before current time where notified=false
" (which catches all previously unsent records)? Would you then set a flag for each type of email you send out successfully?
Or is there a cleverer way that avoids setting flags?
(It was hell coming up with the title and tags for this question — suggestions/edits welcome!)