Rails cron随时随地

时间:2011-03-08 11:55:20

标签: ruby-on-rails cron whenever

我不明白为什么“随时”不起作用

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 <​​/ p>

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'\'''

rails runner“Ping.check_pings” ==&GT;在命令行中工作

我尝试用我的项目在“rails s”中运行而没有 我做错了什么?

2 个答案:

答案 0 :(得分:4)

我只是在猜测,但是......您是在测试开发还是生产?

如果您正在开发中,请不要忘记列出您的日程表.rb:

set :environment, 'development'

你也可以这样做:

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

此致 伊万

答案 1 :(得分: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'

(根本不需要在单个shell-word周围引用。)