Reputation: 2746
In my rails application, users can subscribe to some events. I'd like to send a mail to the user 24 hours before the begining of the the event.
I'm not sure how to implement that. A rake task ? Is there some gems or some best practices to follow ?
Thanks!
EDIT:
I guess that my cron must be run every minute to get each event that starts in 24 hours. But if the cron stops, or it takes more than a minute, I can't skip some emails. In the other way, how can I be sure I'm not sending the same email twice ?
Upvotes: 4
Views: 2956
Reputation: 1
https://github.com/mperham/sidekiq/pull/257
This will help you to solve automatic mailing system in scheduled time!
Upvotes: 0
Reputation: 10403
Check out:
http://railscasts.com/episodes/206-action-mailer-in-rails-3
for sending mail and
http://railscasts.com/episodes/164-cron-in-ruby-revised
for using whenever to set up a cron to call your mailer
EDIT: Just saw your comment. In that case I would look at using something like resque-scheduler or the equivalent with sidekiq:
https://github.com/bvandenbos/resque-scheduler
then you can do things like this:
Resque.enqueue_at(24.hours.from_now, SendFollowUpEmail, :user_id => current_user.id)
sidekiq example:
FollowUpEmailer.perform_in(24.hours.from_now, current_user.id)
Upvotes: 6