无法在rails 3中使用cronjob

时间:2013-04-05 10:30:22

标签: ruby-on-rails ruby-on-rails-3 cron crontab whenever

我会在参考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

输出某些命令

localhost:〜/ project $ when -i

[write] crontab file updated

localhost:〜/ project $ crontab -l <​​/ p>

# 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 $ when

* * * * * /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 

1 个答案:

答案 0 :(得分:1)

你的一切都是正确的,只是你说要在背景中打印一些东西,所以就是这样做,你就能观察到它。

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