2011-03-08 62 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