我按照Whenever教程并安装了gem。我正在使用Ubuntu。我在模型中写了这个方法:
def self.cron_job
puts "am in cron"
InspectionReport.all
logger.info Time.now.to_s
InspectionReport.all.each do |ins|
ins.date = ins.date+1.month
ins.save!
end
end
schedule.rb中的代码:
set :output, "/log/cron.log"
every 1.minute do
runner "InspectionReport.cron_job", :environment => :development
rake update_inspection_reports end
一分钟后什么也没发生。有什么想法吗?
答案 0 :(得分:0)
在schedule.rb文件中尝试此代码。它对我有用:
#for default path related issue
env :PATH, ENV['PATH']
every 1.minute do
runner "InspectionReport.cron_job", :output => 'log/cron.log'
rake update_inspection_reports , :output => 'log/cron.log'
end