我会引用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

在gemfile中
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

然后我输入

本地主机:〜/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

最佳答案

您的所有内容都是正确的,只是您要说的是在cron作业中在后台打印某些内容,因此它就可以执行此操作,并且您可以观察到它。

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

关于ruby-on-rails - 每当在Rails 3中都无法运行cronjob,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15831603/

10-09 08:29