2011-03-08 29 views
2

我不明白,爲什麼 「時」 不工作的Rails的cron與每當

Schedule.rb

every 2.minutes do 
    runner "Ping.check_pings" 
end 

Ping.rb

class Ping < ActiveRecord::Base 
    attr_accessible :LAN, :WAN, :info, :infastructure_id 

    def self.check_pings  
     @monitor_ping = Ping.new()  
     @monitor_ping.WAN = "true" 
     @monitor_ping.save 
    end 
end 

的crontab -l

0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /home/ruben/Monitoring && script/rails runner -e production '\''Ping.check_pings'\''' 

導軌轉輪「Ping.check_pings」 ==>在命令行中工作

我試過了我的項目在「rails s」中運行,沒有 我在做什麼錯了?

+0

由方式:要每2分鐘調用一個cron作業,你可以使用'*/2 * * * * ...' – Wukerplank 2011-03-08 14:13:53

回答

0
'cd /home/ruben/Monitoring && script/rails runner -e production '\''Ping.check_pings'\''' 

我認爲這個字符串上的字符轉義不正確;看看production '\''一塊,第一個'關閉字符串,然後你逃脫'沒有打開字符串。試試這個:

'cd /home/ruben/Monitoring && script/rails runner -e production \'Ping.check_pings\'' 

或本:

"cd /home/ruben/Monitoring && script/rails runner -e production 'Ping.check_pings'" 

或本:

'cd /home/ruben/Monitoring && script/rails runner -e production Ping.check_pings' 

(你可能不需要周圍的單殼字報價在所有:)

+0

我試過它們都沒有工作):我會創建它奇怪的是,這是問題,因爲cr on是由「when」自動生成的。有沒有可能強制crons,所以我可以看到他們是否拋出錯誤或什麼? – Nostrodamus 2011-03-08 12:17:11

+0

@Nostrodamus,如果cron正在運行,它會每兩分鐘運行一次,至少該部分是正確的。 :)如果需要,你可以使用'echo date>/tmp/test'作爲命令。 (使用'crontab -e'編輯現有的crontab進行更改。) – sarnold 2011-03-08 12:19:09

+0

這樣做,每2分鐘測試文件就會被修改。我的cron沒什麼問題。它可能是一個權限問題? – Nostrodamus 2011-03-08 12:33:54

4

我只是在猜測,但是...你正在測試開發還是生產?

如果您正在開發中,不要忘記把你的schedule.rb:

set :environment, 'development' 

你也可以這樣做:

every 10.minutes do 
    runner "User.vote", environment => "development" 
end 

問候 伊萬

+0

我試着你的建議,但仍然獲得-e生產。我更新了crontab。任何想法爲什麼發生這種情況? – 2014-05-22 13:29:18