ruby - 不承认 resque worker 已经启动

标签 ruby resque god

我在运行 resque workers from god 时遇到问题。

这是我的上帝配置

num_workers = 9 
queue       = '*'
current_path = "/u/apps/narg/current"

God.pid_file_directory = "/u/apps/narg/current/tmp/pids"
num_workers.times do |num|
  God.watch do |w|
    w.name     = "resque-#{num}"
    w.group    = "resque_all"
    w.interval = 30.seconds
    w.env      = {"QUEUE"=>queue, "RAILS_ENV"=>"production",
             'PIDFILE' => "#{current_path}/tmp/pids/#{w.name}.pid" }
w.start    = "cd #{current_path} ; bundle exec rake environment resque:work"
w.log      = "#{current_path}/log/god-#{w.name}.log"
w.pid_file = "#{current_path}/tmp/pids/#{w.name}.pid"
w.uid = 'root'
w.gid = 'root'
w.behavior(:clean_pid_file)
# retart if memory gets too high
w.transition(:up, :restart) do |on|
  on.condition(:memory_usage) do |c|
    c.above = 150.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
    c.interval = 5
  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

当我启动上帝时,当工作人员正在工作时,一切看起来都很好,并且它运行所有转换到:向上。

但是当worker不在运行的时候,启动后就停止了。 worker 实际上已经启动,pid 文件也是正确的。只有上帝不明白:

 ** [out :: narg-wrk02] I [2012-08-23 11:40:48]  INFO: resque-7 move 'unmonitored' to 'init'
 ** [out :: narg-wrk02] I [2012-08-23 11:40:48]  INFO: resque-7 moved 'unmonitored' to 'init'
 ** [out :: narg-wrk02] I [2012-08-23 11:40:48]  INFO: resque-7 [trigger] process is not running (ProcessRunning)
 ** [out :: narg-wrk02] I [2012-08-23 11:40:48]  INFO: resque-7 move 'init' to 'start'
 ** [out :: narg-wrk02] I [2012-08-23 11:40:48]  INFO: resque-7 before_start: deleted pid 
 ** [out :: narg-wrk02] I [2012-08-23 11:40:48]  INFO: resque-7 start: cd /u/apps/narg/current ; bundle exec rake environment resque:work

如前所述,工作人员已启动并运行良好。 pid 文件也包含正确的 pid。

如果我现在 kill god 并重新启动它,它会很好地识别正在运行的 worker 并转换到 :up..

有什么想法或建议吗?

最佳答案

尝试改变

w.start = "cd #{current_path} ; bundle exec rake environment resque:work"

w.start = "cd #{current_path} ; bundle exec rake environment resque:work &"

这为我解决了同样的问题。

关于ruby - 不承认 resque worker 已经启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12089211/

相关文章:

ruby-on-rails - 图像重应用的最佳 Ruby on Rails 架构

ruby-on-rails-3 - sidekiq true god.rb 从不运行我的 worker ,而来自终端的相同命令呢?

ruby - 上帝不会阻止 unicorn

ruby-on-rails - 上帝没有运行 : The server is not available (or you do not have permissions to access it)

linux - 神 : Unable to start without sudo

ruby-on-rails - 用于 ruby​​ 1.9 和 rails 的 soap 客户端

ruby - 在 Ruby 中,符号 "=>"在方法的参数列表中表示什么?

Ruby 2.2.1 - string.each_char 没有为重复出现的字母提供唯一索引 - 我该怎么做?

javascript - 在 Ruby On Rails 中获取纬度和经度

ruby-on-rails - Ruby resque 后台 CSV 导入不运行