【问题标题】:First time use of God gem, not shutting down deamons第一次使用God gem,不关闭守护进程
【发布时间】:2014-11-15 09:30:12
【问题描述】:

这是我第一次使用God gem。当我运行命令god terminate 时,它不会关闭现有任务。所以下次我再次运行上帝脚本时,它只会翻倍。

我看到了 Resque 用于终止 Rogue 生成的示例脚本,但不完全了解如何修改我的脚本。

我运行的命令

god -c config/resque.god
god -c config/stale.god

我的 resque.god 文件:

RAILS_ROOT = File.dirname(File.dirname(__FILE__))

God.watch do |w|
    w.name          = "android_msg"
    w.group         = "resque-group"
    w.interval      = 30.seconds
    w.start         = "cd #{RAILS_ROOT} && rake resque:work QUEUE='android_message'"
    w.start_grace   = 10.seconds

    # restart if memory gets too high
    w.transition(:up, :restart) do |on|
        on.condition(:memory_usage) do |c|
        c.above = 350.megabytes
        c.times = 2
        end
    end

    # determine the state on startup
    w.transition(:init, { true => :up, false => :start }) do |on|
      on.condition(:process_running) do |c|
        c.running = true
      end
    end

    # determine when process has finished starting
    w.transition([:start, :restart], :up) do |on|
      on.condition(:process_running) do |c|
        c.running = true
        c.interval = 5.seconds
      end

      # failsafe
      on.condition(:tries) do |c|
        c.times = 5
        c.transition = :start
        c.interval = 5.seconds
      end
    end

    # start if process is not running
    w.transition(:up, :start) do |on|
        on.condition(:process_running) do |c|
        c.running = false
    end
  end
end


God.watch do |w|
    w.name          = "apn_sender"
    w.group         = "resque-group"
    w.interval      = 30.seconds
    w.start         = "cd #{RAILS_ROOT} && rake apn:sender"
    w.start_grace   = 10.seconds

    # restart if memory gets too high
    w.transition(:up, :restart) do |on|
        on.condition(:memory_usage) do |c|
        c.above = 350.megabytes
        c.times = 2
        end
    end

    # determine the state on startup
    w.transition(:init, { true => :up, false => :start }) do |on|
      on.condition(:process_running) do |c|
        c.running = true
      end
    end

    # determine when process has finished starting
    w.transition([:start, :restart], :up) do |on|
      on.condition(:process_running) do |c|
        c.running = true
        c.interval = 5.seconds
      end

      # failsafe
      on.condition(:tries) do |c|
        c.times = 5
        c.transition = :start
        c.interval = 5.seconds
      end
    end

    # start if process is not running
    w.transition(:up, :start) do |on|
        on.condition(:process_running) do |c|
        c.running = false
    end
  end
end

陈旧的神

# This will ride alongside god and kill any rogue stale worker
# processes. Their sacrifice is for the greater good.

WORKER_TIMEOUT = 60 * 10 # 10 minutes

Thread.new do
  loop do
    begin
      `ps -e -o pid,command | grep [r]esque`.split("\n").each do |line|
        parts   = line.split(' ')
        next if parts[-2] != "at"
        started = parts[-1].to_i
        elapsed = Time.now - Time.at(started)

        if elapsed >= WORKER_TIMEOUT
          ::Process.kill('USR1', parts[0].to_i)
        end
      end
    rescue
      # don't die because of stupid exceptions
      nil
    end

    sleep 30
  end
end

【问题讨论】:

    标签: ruby-on-rails-3 resque


    【解决方案1】:

    我认为你需要这样做:

    god -c config/resque.god ;; starts god with the given config
    god load config/stale.god ;; loads the given config into an already running god instance
    

    【讨论】:

      【解决方案2】:

      以下命令对我不起作用:

      god load config/stale.god
      

      挖了一圈,发现可能只是在resque.god的顶部才需要

      require 'stale.god'
      

      【讨论】:

        猜你喜欢
        • 2014-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-13
        • 2012-10-03
        • 1970-01-01
        • 1970-01-01
        • 2010-11-13
        相关资源
        最近更新 更多