Reputation: 491
I'm relatively new to actionmailer however I have set up forgot password emails and have them running as delayed jobs already. I would like to set up dynamic email reminders where users can select options like "Remind me ___ minutes/hours/days" before an event start and have it send an email reminder. I don't want to leave it completely open-ended and will have a dropdown with the following options:
What is the best/most efficient way to accomplish this? Can the delayed jobs run_at function accomplish this or should I write a delivery method for each of the dropdown options calling something that says to deliver the mail at
event_start - 60.minutes
or something like that? My app is using Rails 3.0.11 and this is different from a daily cron task because these could run at any time. Also, will it cause any problems with the delayed jobs if a user is able to edit the event dates changing the start and end dates?
Upvotes: 2
Views: 1842
Reputation: 12335
Probably best to store this info in a database, and set up a single delayed job for each time period before each event.
ie. For event A, only 6 delayed jobs, one 1 day before event, another 1 hour before, another 30 mins before, ...
Then the delayed job can look in the database for which users need the reminder email.
If instead you set up the delayed job when the user selected it, then what if they change their mind? It would make it harder to delete/change when the delayed job runs for a particular user.
Also if many users want emails at once, it might cause traffic problems with multiple jobs trying to run at the same time. Instead, a single job emailing the list of users one at a time will cause less of a problem.
Upvotes: 3