简体   繁体   中英

Rake Task using Whenever Gem

I want to send emails daily weekly and monthly accordingly what user has selected. How can I do it using whenever gem.

Below is my rake file:

namespace :send_trending_deals do
  desc "TODO"
  task email_trending_deals: :environment do
    @app_users = AppUser.joins(:notification).where("recieve_trending_deals = ?", true).to_a
    @app_users.each do |app_user|
      DealNotifier.send_trending_deal(app_user).deliver_now
      puts "#{app_user.id} Email sent successfully"
    end
  end
end  

Schedule.rb:

every 4.hours do
    rake "send_trending_deals:email_trending_deals"
end

Daily

every :day, at: '10:00' do
   #run task
end

Weekly

every :sunday, at: '13:00' do
   #run task
end

Monthly

every :month, at: '12:00' do
   #run task
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM