So I’m just needing a bit of advice here.
I have an app that I deployed to heroku, and I have mailers set up so when things like ‘record is added’ mailers run and send email to users.
One type of mailer I’d like to create is one that goes out on a specific day.
For example, I might say, send mailer on November 3rd at 6:00 am.
How would I go about scheduling that? I mean I can’t really use .deliver_later because I realize when the dyno goes to sleep the job will no longer be queued (at least that’s how I understand it)
SO I supposed I need to use something like Redis, or Sidekiq, or perhaps Heroku Scheduler? Any advice on this subject would be extremely helpful. I’ve read a few SO posts about this, but I’m still lost.
Thank you in advanced.
2
Answers
I haven’t used Heroku. In my case, I use
sidekiq
andsidekiq-cron
to do some cron jobYou can achieve it using Sidekiq.
Sidekiq allows you to schedule the time when a job will be executed. You use
perform_in(interval_in_seconds, *args)
orperform_at(timestamp, *args)
rather than the standardperform_async(*args)
:This is useful for example if you want to send the user an email 3 hours after they sign up. Jobs which are scheduled in the past are enqueued for immediate execution.
In your case, you can achieve it using
perform_at(timestamp, *args)
have a look at code –More information here –
https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs