I need to send users an email at some point far in the future, in the order of 30 days, the exact time must be random.
My plan is:
When a user submits a specific form, I immediately generate a random number of days and calculate the future date when the email should be sent. I then save that date/time to a specific collection to the db (table for you SQL people), with the email address and other relevant data.
I then create a background task that runs a every few hours (4 times per day). That task checks the db collection for any entries that have a date/time that passed the current date/time. If any entries are found, those emails are sent and the documents (records) are deleted from the db.
Like this if anything goes wrong and the server shuts down at some point during the 30 days, when it comes back online it just resumes checking the db and sends whatever is in the "queue". To maintain the illusion of randomness I can randomize the intervals at which the background task runs.
Does anyone see a problem with the approach or maybe have a simpler solution?