[英]How to send mails automatically using whenever gem
我曾經用過gem來每天發送郵件,但沒有發送。我正在使用amazon linux ec2
實例。 請看一下我的代碼。
schedule.rb:
every 5.minutes do
runner "Listings.today_expired_spaces"
end
Listings.rb :(模型文件)
def today_expired_spaces
@list=List.find_by_date(Date.today)
UserMailer.today_expired_list(@list).deliver
end
在生產中:
運行這些命令后,我得到這樣的響應
1.每當-w
[寫]寫入crontab文件
2.whenever -i [寫入] crontab文件已更新
3.每當
0,5,10,15,20,25,30,35,40,45,50,55 * * * * / bin / bash -l -c'cd / home / ubuntu / my_server && bundle exec腳本/ railsrunner -e生產'\\''Spaces.today_expired_spaces'\\'''
[消息]上面是您的計划文件轉換為cron語法; 您的crontab文件未更新。
[消息]運行`whenever --help'以獲得更多選項。
請提供解決方案。
您應該在lib/tasks
文件夾中創建一個rake task
,並將該任務包含在config/schedule.rb
何時計划文件中
在lib/tasks/send_mail_bang_bang.rake
(文件名僅作為示例)
require 'rake'
namespace :task_namespace do
desc 'task description'
task :send_mail => :environment do
# call Listing method to send mail
Listings.today_expired_spaces
end
end
在config/schedule.rb
every 5.minutes do
rake 'task_namespace:send_mail'
end
你可以閱讀更多有關rake任務在這里的“自定義耙任務”部分
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.