I have a rake task that is supposed to send a mail every day to users that has their daily field == true. (I already have a mail implementation in my project that is working, it sends a mail at the creation of an account and for password resetting). I'm using Whenever gem
The thing is, since I'm not in production, I don't know how I could test if it works.
Here is my UserMailer :
def daily_mail(user)
@user = user
mail to: user.email, subject: "Mail journalier"
end
My rake task :
desc "Send email to users"
task :email_sender => :environment do |_, args|
User.find_each do |user|
UserMailer.daily_mail(user).deliver if user.daily == true
end
end
And my schedule.rb :
every :day, :at => '12pm' do # Use any day of the week or :weekend, :weekday
rake "email_sender"
end
I did this after looking tutorials :
whenever --update-crontab store (and tried with --set too)
I tried to do a crontab -l and I get this :
# Begin Whenever generated tasks for: store
0 12 * * * /bin/bash -l -c 'cd /Users/Marco/Documents/TBProject && RAILS_ENV=production bundle exec rake email_sender --silent'
# End Whenever generated tasks for: store
# Begin Whenever generated tasks for: /Users/Marco/Documents/TBProject/config/schedule.rb
0 12 * * * /bin/bash -l -c 'cd /Users/Marco/Documents/TBProject && RAILS_ENV=production bundle exec rake email_sender --silent'
# End Whenever generated tasks for: /Users/Marco/Documents/TBProject/config/schedule.rb
Is their a way to test (or to know) if my task will work on production ?
Aucun commentaire:
Enregistrer un commentaire