0

我目前正在使用 God 启动 6 个 resque 工作进程。Resque 表明他们已经开始工作并且一切正常。有时,工作进程会失去识别并不再是已知的 resque 工作进程。我正在寻找的是一种重新启动该过程或让 resque-web 再次识别它的方法。奇怪的是它仍然在后台运行并分叉任务来处理它们,我可以看到 resque-web 上的数量减少了,但它并没有显示任何工作人员正在运行。我查看了他们的 stale.god 脚本,但这不起作用,因为该过程似乎在从 resque-web 识别中删除后继续检索工作。这是我的设置:

#resque-production.god

6.times do |num|
  God.watch do |w|
    w.name = "resque-#{num}"
    w.group = "resque"
    w.interval = 30.seconds
    w.env = { 'RAILS_ENV' => 'production' }
    w.dir = File.expand_path(File.join(File.dirname(__FILE__)))
    w.start = "bundle exec rake environment RAILS_ENV=production resque:workers:start"
    w.start_grace = 10.seconds
    w.log = "/var/www/loadmax/shared/log/resque-worker.log"

    # restart if memory gets too high
    w.transition(:up, :restart) do |on|
      on.condition(:memory_usage) do |c|
        c.above = 200.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
end 

下一个文件用于连接到一个 redis 服务器并设置优先级。

#resque.rake 
require 'resque/tasks'
Dir.glob("#{Rails.root}/app/workers/*.rb") do |rb|
  require rb
end
task "resque:setup" => :environment do
  resque_config = YAML.load_file(Rails.root.join("config","resque.yml"))
  ENV['QUEUE'] = resque_config["priority"].map{ |x| "#{x}" }.join(",") if ENV['QUEUE'].nil?
end
task "resque:workers:start" => :environment do
  threads = []
  q = [1,2]
  resque_config = YAML.load_file(Rails.root.join("config","resque.yml"))
  threads << Thread.new(q){ |qs|
    %x[bundle exec rake environment RAILS_ENV=#{Rails.env} resque:work QUEUE=#{resque_config["priority"].map{ |x| "#{x}" }.join(",")} ]
  }
  threads.each {|aThread| aThread.join }
end

我一直在寻找解决方案,僵尸进程、陈旧进程和退出进程似乎都不是解决方案。我是god -c /path/to/god用来启动的。

让我知道我是否需要提供任何其他内容或更清楚。感谢所有的帮助!

4

1 回答 1

0

我最终把 redis 和工人放在了同一个盒子上,从那以后他们一直在正常工作。

于 2013-06-04T13:52:05.117 回答