凌波的上帝复仇过程

时间:2013-03-01 20:55:22

标签: ruby ruby-on-rails-3 resque god

我正在使用上帝启动6个resque工作进程。 Resque show表明他们已经开始工作,一切正常。有时,工作进程会失去识别,并且不再是已知的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开始。

如果我需要提供任何其他内容或更清楚,请告诉我。谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我最终将redis放在与工人相同的盒子上,从那以后它们一直运作正常。