-1

I have this scenario: A user buys a product and when two days have passed after the transaction has been processed, I need to send a mail notification to buyer.

At this moment my idea is to use whenever gem and check build a cron job to check in each day and if 2 days have passed and if true, cron job will send mail notification.

I don't know if is ok to do this... Can you give me better solution?

kitz
  • 879
  • 2
  • 9
  • 24

2 Answers2

1

You can use ActiveJob with perform_later, like:

NotificationSendJob.set(wait: 2.days).perform_later(record)

Note that not all backends support this. You can see check feature matrix here: http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html

katafrakt
  • 2,438
  • 15
  • 19
1

Rather that using whenever,I would suggest using sidekiq which is a background processing library. The cron job has to be executed everyday(in your particular case). It doesn't consider whether a mail has to be sent or not. The job will still be executed even if no mails are to be sent, which is a wrong approach.

You can use a background processing library like sidekiq to schedule the job in the background. checkout https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs

Prasad Surase
  • 6,486
  • 6
  • 39
  • 58