Rails cron 与每当

发布于 2024-10-20 14:28:08 字数 743 浏览 6 评论 0原文

我不明白为什么“每当”不起作用

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

Rails runner "Ping.check_pings" ==>在命令行中工作

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

I don't understand why "whenever" does not work

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

rails runner "Ping.check_pings"
==> Works in command line

I tried it with my project running in "rails s" and without
What am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞觅青森が 2024-10-27 14:28:09

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

如果您正在开发中,请不要忘记安排您的日程安排。rb:

set :environment, 'development'

您也可以这样做:

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

问候
伊万

I am just guessing, but... Are you testing on development or production?.

If your are in development, don't forget to put on your schedule.rb:

set :environment, 'development'

Also you can do this:

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

Regards
Ivan

似狗非友 2024-10-27 14:28:09
'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'"

或这个:(

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

您可能根本不需要在单个 shell 单词周围加上引号。:)

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

I think the character escaping is incorrect on this string; look at the production '\'' piece, the first ' closes the string, then you're escaping a ' without a string being open. Try this:

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

or this:

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

or this:

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

(you might not need quotes around the single shell-word at all. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文