5

我遵循参考https://github.com/javan/whenever的所有步骤

在 schedule.rb 中

require 'yaml'
set :environment, 'production'
set :output, {
    :error    => "/log/error.log",
    :standard => "/log/cron.log" 
}

every 1.minute do
   runner "User.weekly_update"
end

在宝石文件中

gem 'whenever', :require => false

一些命令的输出

本地主机:~/project$ 每当 -i

[write] crontab file updated

本地主机:~/project$ crontab -l

# Begin Whenever generated tasks for: /home/bacancy/project/config/schedule.rb
* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e     production '\''User.weekly_update'\'' >> /log/cron.log 2>> /log/error.log'

# End Whenever generated tasks for: /home/bacancy/project/config/schedule.rb

# Begin Whenever generated tasks for: store
* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e  development '\''User.weekly_update'\'''

# End Whenever generated tasks for: store

# Begin Whenever generated tasks for: lapulguilla

# End Whenever generated tasks for: lapulguilla

然后我输入

localhost:~/project$ 任何时候

* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e    production '\''User.weekly_update'\'' >> /log/cron.log 2>> /log/error.log'

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

在用户模型中,我有定义 self.weekly_update

def self.weekly_update
  puts "cronjobs is called in every minutes"
end 
4

1 回答 1

1

你的一切都是正确的,只是你说 cron 作业在后台打印一些东西,所以它正在这样做并且你能够观察它。

相反,您应该尝试创建或销毁一些记录以感受我认为的变化:)

于 2013-04-29T17:33:05.070 回答