Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 上帝-在现有进程仍在停止时启动新进程_Ruby_Monitoring_God - Fatal编程技术网

Ruby 上帝-在现有进程仍在停止时启动新进程

Ruby 上帝-在现有进程仍在停止时启动新进程,ruby,monitoring,god,Ruby,Monitoring,God,使用God(godrb.com),我试图编写一个配方,在部署应用程序时,无论现有进程的状态如何,都可以启动一个新进程。现有进程需要较长的运行超时才能完成当前任务,但新进程应该使用新部署的代码立即启动 我现在设置了一个300秒的停止超时时间,但是在启动新进程之前要等待整个300秒 God.watch do |w| w.name = "sidekiq" w.interval = 30.seconds w.start = "bash -lc 'cd /path/to/current &am

使用God(godrb.com),我试图编写一个配方,在部署应用程序时,无论现有进程的状态如何,都可以启动一个新进程。现有进程需要较长的运行超时才能完成当前任务,但新进程应该使用新部署的代码立即启动

我现在设置了一个300秒的停止超时时间,但是在启动新进程之前要等待整个300秒

God.watch do |w|
  w.name = "sidekiq"
  w.interval = 30.seconds
  w.start = "bash -lc 'cd /path/to/current && ./bin/sidekiq -P /path/to/shared/pids/sidekiq.pid'"
  w.stop  = "bash -lc 'kill -USR1 `cat /path/to/shared/pids/sidekiq.pid`'"
  w.stop_timeout = 300.seconds
  w.pid_file = "/path/to/shared/pids/sidekiq.pid"
  w.behavior(:clean_pid_file)
end
在本例中,
kill-USR1
告诉sidekiq完成处理任何当前作业,但不再进行任何工作


我希望保留现有工作进程的300秒超时,但在kill命令运行后立即启动新进程。

我认为您必须定义一些转换

这是我的上帝

# I'm using Rails
rails_env = ENV['RAILS_ENV'] || 'development'
rails_root = '/path/to/current'
pid_file = "#{rails_root}/tmp/pids/sidekiq.pid"

God.watch do |w|
  w.dir = rails_root
  w.name = "sidekiq"
  w.interval = 30.seconds
  w.env = {'RAILS_ENV' => rails_env, 'BUNDLE_GEMFILE' => "#{rails_root}/Gemfile"}
  w.uid = 'deployer'
  w.gid = 'staff'

  w.start = "cd #{rails_root}; bundle exec sidekiq -e #{rails_env} -C #{rails_root}/config/sidekiq.yml -i #{i} -P #{pid_file}&"
  w.stop = "cd #{rails_root}; bundle exec sidekiqctl stop #{pid_file} 10"
  w.restart = "#{w.stop} && #{w.start}"
  w.start_grace = 15.seconds
  w.restart_grace = 15.seconds
  w.pid_file = pid_file
  w.log = "#{rails_root}/log/sidekiq.log"

  # clean pid files before start if necessary
  w.behavior(:clean_pid_file)

  # 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
    end

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

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

  # lifecycle
  w.lifecycle do |on|
    on.condition(:flapping) do |c|
      c.to_state = [:start, :restart]
      c.times = 5
      c.within = 5.minute
      c.transition = :unmonitored
      c.retry_in = 10.minutes
      c.retry_times = 5
      c.retry_within = 2.hours
    end
  end
end

你看过独角兽是怎么做到的吗?这使得独角兽有责任培养新员工,并让这些新员工杀死旧员工。是的,但这一功能是独角兽的一部分。我正试图用任何通用的过程来完成类似的事情。