Reputation: 6015
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
Upvotes: 0
Views: 325
Reputation: 2256
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
Upvotes: 3