2013-10-12 106 views
1

我試圖在我的rails應用程序中實現cron作業,並且對於cron來說是全新的。我使用whenever寶石軌道3每當cron作業不工作(Rails 3)

這些步驟,我已經做了:

在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') 

我沒有得到,事情會出錯。有人能幫我解決嗎?

會真的很感激它。

謝謝。

回答

0

已解決。我在schedule.rb開頭添加了這條路徑:

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

現在crons工作得很完美。