skip to Main Content

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


  1. I haven’t used Heroku. In my case, I use sidekiq and sidekiq-cron to do some cron job

    Login or Signup to reply.
  2. You 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) or perform_at(timestamp, *args) rather than the standard perform_async(*args):

    MyWorker.perform_in(3.hours, 'mike', 1)
    MyWorker.perform_at(3.hours.from_now, 'mike', 1)
    

    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 –

    time_stemp = DateTime.parse("09/11/2020 06:00 AM")
    SendMailToUserWorker.perform_at(time_stemp, args)
    

    More information here –
    https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search