Cron 作业不适用于 Whenever gem、rails 5
Cron job not working for Whenever gem, rails 5
我正在使用 ide 云 9
Rails5
我每次都安装 gem。
gem 'whenever', :require => false
schedule.rb:
set :output, "#{path}/log/cron.log"
every 2.minutes do
rake "subscription:send_mails"
end
namespace :subscription do
desc "Send dayly mails with new projects"
task send_mails: :environment do
Subscriber.where.not(categories: []).find_each do |subscriber|
projects = Project.where(categories: subscriber.categories, created_at: 1.days.ago )
SubscriptionMailer.send_email_with_new_projects(subscriber, projects).delivery_now
end
end
end
运行 在命令行中:
bundle exec whenever
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 /home/ubuntu/workspace && RAILS_ENV=production bundle exec rake subscription:send_mails --silent >> /home/ubuntu/workspace/log/cron.log 2>&1'
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
现在 运行在开发模式下安装本地服务器。我没有看到任何 evidence 代码实际上是 运行。 log/cron.log 为空。有没有我没有做的步骤?
除非您使用的是 SSH 工作区,否则 Cron 作业无法在 Cloud9 上运行。
我正在使用 ide 云 9 Rails5
我每次都安装 gem。
gem 'whenever', :require => false
schedule.rb:
set :output, "#{path}/log/cron.log"
every 2.minutes do
rake "subscription:send_mails"
end
namespace :subscription do
desc "Send dayly mails with new projects"
task send_mails: :environment do
Subscriber.where.not(categories: []).find_each do |subscriber|
projects = Project.where(categories: subscriber.categories, created_at: 1.days.ago )
SubscriptionMailer.send_email_with_new_projects(subscriber, projects).delivery_now
end
end
end
运行 在命令行中:
bundle exec whenever
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 /home/ubuntu/workspace && RAILS_ENV=production bundle exec rake subscription:send_mails --silent >> /home/ubuntu/workspace/log/cron.log 2>&1'
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
现在 运行在开发模式下安装本地服务器。我没有看到任何 evidence 代码实际上是 运行。 log/cron.log 为空。有没有我没有做的步骤?
除非您使用的是 SSH 工作区,否则 Cron 作业无法在 Cloud9 上运行。