无法在rails 3中使用cronjob [英] Unable to run cronjob using whenever in rails 3

查看:221
本文介绍了无法在rails 3中使用cronjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照所有步骤,参考 https://github.com/javan/whenever



in schedule.rb

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

every 1.minute do
runnerUser.weekly_update
end

 

 

,:require => false

某些命令的输出



localhost :〜/ project $ when -i

  [write] crontab文件更新

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

  #Begin每当生成的任务:/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'

#结束每当生成的任务:/home/bacancy/project/config/schedule.rb

#开始每当生成的任务:store
* * * * * / bin / bash -l -c'cd / home / bacancy / project&&脚本/ rails runner -e开发'\''User.weekly_update'\'''

#结束每当生成的任务:store

#开始每当生成的任务for:lapulguilla

#End每当生成的任务:lapulguilla

我输入



localhost:〜/ project $ every

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

## [message]上面是你的日程表文件转换为cron语法;您的crontab文件没有更新。
## [message]运行`whatever --help'获取更多选项。

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

  def self.weekly_update 
puts每分钟调用cronjobs
end


解决方案

你的一切是正确的,它只是你正在说cron工作在背景打印的东西,所以它是这样做和你



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


i follow all the steps for whenever with reference to https://github.com/javan/whenever

in 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

in gemfile

gem 'whenever', :require => false

output of some command

localhost:~/project$ whenever -i

[write] crontab file updated

localhost:~/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

and then i type

localhost:~/project$ whenever

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

In User model i have definition self.weekly_update

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

解决方案

Your everything is correct, its just that you are saying to cron job to print something in background, so it is doing that and you are able to observe it.

Instead you should try create or destroy some records to feel the changes i think :)

这篇关于无法在rails 3中使用cronjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆