0

In my application there are posts which are going to expire in certain time of a day.

After the expiration the customer needs to notify through emails.

I have used Rails cron whenever for in each 1 minute and it makes expire the post at the specified time and sends the email to customers.

Schedule.rb

every 1.minutes do
  rake "ad_has_expired_task"
end

Will be this a better way?

Any help is appreciated.

Thanks

Debadatt
  • 5,935
  • 4
  • 27
  • 40
  • I think that's fine. Another option would be to use `delayed_job` or `sidekiq` to add a scheduled email on the time of expiration. – jvnill Mar 27 '14 at 12:44

1 Answers1

3

For small app, this way is good, but for a bigger app, that may keep cpu busy.

Here is a solution from my site.

gem sidekiq
gem whenever

in scheduler.rb

every 1.day do
  rake "scan_expired_task"
end

in rake taks scan_expired_task.rake

if post.will_expire_today
   MyMailerWoker.perform_async(related_user_ids, post.expired_at-Time.now)
end

Then you write your mailer program in your MyMailerWoker

The codes above can't be executed directly, you need to customize it by your business.

Hope it helps.

reference:

https://github.com/mperham/sidekiq/wiki/Getting-Started

Chuanpin Zhu
  • 2,226
  • 1
  • 21
  • 21