【问题标题】:Whenever cron jobs not working (Rails 3)每当 cron 作业不工作时(Rails 3)
【发布时间】:2013-10-20 15:44:58
【问题描述】:

我正在尝试在我的 rails 应用程序中实现 cron 作业,并且对 crons 完全陌生。我在 Rails 3 中使用whenever gem。

这些是步骤,我已经完成了:

在 Gemfile 中

gem 'whenever', :require => false   

然后跑,

wheneverize .

这就是我的 config/schedule.rb 的样子:

set :environment, :development

set :path, "/home/pc/Workspace/pep1"


every 1.minutes do
runner "Demo.update_time_slot"
command "rm -rf /tmp/cache"
end

我的演示模型包含:

class << self
def update_time_slot
    .......
end
end

在终端上,我运行了命令,

whenever --update-crontab pep1
whenever -i

但看起来,cron 文件没有被执行。但是当我在 Rails 控制台上执行 Demo.update_time_slot 时,它工作正常。

crontab -l 的输出是:

            # Begin Whenever generated tasks for: pep1
    * * * * * /bin/bash -l -c 'cd /home/pc/Workspace/pep1 && script/rails runner -e development '\''Demo.update_time_slot'\'''

    * * * * * /bin/bash -l -c 'rm -rf /tmp/cache'

    # End Whenever generated tasks for: pep1

    # Begin Whenever generated tasks for: /home/pc/Workspace/pep1/config/schedule.rb
    * * * * * /bin/bash -l -c 'cd /home/pc/Workspace/pep1 && script/rails runner -e development '\''Demo.update_time_slot'\'''

    * * * * * /bin/bash -l -c 'rm -rf /tmp/cache'

    # End Whenever generated tasks for: /home/pc/Workspace/pep1/config/schedule.rb

“grep CRON /var/log/syslog”的输出是:

Oct 12 22:37:01 IdeaPad-S400 CRON[10845]: (pc) CMD (/bin/bash -l -c 'rm -rf /tmp/cache')
Oct 12 22:37:01 IdeaPad-S400 CRON[10846]: (pc) CMD (/bin/bash -l -c 'cd /home/mona/Workspace/pep1 && script/rails runner -e development '\''Demo.update_time_slot'\''')
Oct 12 22:37:01 IdeaPad-S400 CRON[10847]: (pc) CMD (/bin/bash -l -c 'cd /home/mona/Workspace/pep1 && script/rails runner -e development '\''Demo.update_time_slot'\''')
Oct 12 22:37:01 IdeaPad-S400 CRON[10852]: (pc) CMD (/bin/bash -l -c 'rm -rf /tmp/cache')

我不知道哪里出了问题。有人可以帮我解决这个问题吗?

真的很感激。

谢谢。

【问题讨论】:

    标签: ruby-on-rails-3.2 whenever


    【解决方案1】:

    解决了。我在 schedule.rb 的开头添加了这个路径:

    env :PATH, '/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games'
    

    现在 crons 运行良好。

    【讨论】:

      猜你喜欢
      • 2011-10-22
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 2017-11-05
      • 2016-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多