每当+梅勒不在一起工作时

问题描述 投票:0回答:2

我需要每周发一些电子邮件。我安装了邮件并做了几次测试。工作正常。

但我无法使用Whenever自动发送电子邮件。在各种论坛中搜索过但仍无法修复。

型号/ HrCurriculumIntern

def self.send_reply_interns
  @users = HrCurriculumIntern.where(:answer_sent => t('labels.n'))
  InternMailer.send_reply_interns(@users).deliver
end

梅勒/ InternMailer

default :from => "[email protected]"

def send_reply_interns(users)
  @users = users   
  mail(:to => "<[email protected]>", :subject => t('subjects.send_reply_interns'), :from => "[email protected]")
end

配置/ schedule.rb

set :environment, :development

every 2.minutes do
 runner "HrCurriculumInterns.send_reply_interns"
end

我按照以下步骤操作:我按照以下步骤操作:

什么时候。

每当

0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /var/www/form/3216/email/trunk && script/rails runner -e development '\''HrCurriculumInterns.send_reply_interns'\'''

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.

每当-update-crontab

 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /var/www/form/3216/email/trunk && script/rails runner -e development '\''HrCurriculumInterns.send_reply_interns'\'''

 ## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
 ## [message] Run `whenever --help' for more options.

我看不出问题,有什么建议吗?

ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2 whenever
2个回答
1
投票

使用快捷方式“when -w”编写crontab。看起来你使用“when -update-crontab”而不是“when -update-crontab”。因此,您的命令都没有实际编写crontab文件。答案应该是

[write] crontab file updated

之后使用“crontab -l”来验证是否写入了正确的cron。


0
投票

我找到了解决方案。

我的代码错了。我做了一些改动:

梅勒/ intern_mailer.rb

def send_reply_interns
  @users = HrCurriculumIntern.where(:answer_sent => t('labels.n'))  
  mail(:to => "<[email protected]>", :subject => t('subjects.send_reply_interns'), :from => "[email protected]")
end

型号/ hr_curriculum_intern.rb

def self.send_reply_interns
  InternMailer.send_reply_interns.deliver
end

schedule.rb

set :environment, :development

every 2.minutes do
  runner "HrCurriculumIntern.send_reply_interns"
end

它的作品现在\ o /

谢谢你的答复

© www.soinside.com 2019 - 2024. All rights reserved.