1

有没有可能让上帝依次启动两个过程?

我正在使用依赖 Redis 的 Sidekiq。我想启动 Redis,然后启动 Sidekiq,我设置了两个独立的手表,它们可以独立工作,但是当我运行时:

$ god -c "./config.god" -D

似乎上帝试图同时启动两者,导致 Sidekiq 出错,因为它可以t 连接到 Redis 服务器。

我给上帝的配置文件如下:

# config.god
PROJECT_ROOT = ENV['PROJECT_ROOT'] || "/Path/to/app"

God.watch do |w|
  w.name = "redis-server"
  w.group = 'conversion-api'
  w.interval = 30.seconds
  w.start = "/usr/local/Cellar/redis/2.4.16/bin/redis-server"
end

God.watch do |w|
  w.name = "sidekiq"
  w.group = 'conversion-api'
  w.interval = 20.seconds
  w.dir = ENV['PROJECT_ROOT'] 
  w.start = "bundle exec sidekiq -v -C #{PROJECT_ROOT}/config.yml -r #{PROJECT_ROOT}/app.rb -c 10"
  w.stop = "bundle exec sidekiqctl stop #{PROJECT_ROOT}/tmp/pids/sidekiq.pid 5"
  w.keepalive
  # Don't pass in a pid file location. Let God handle things. Leaving a pid file location in
  # the sidekiq config.yml seems to be harmless though and it lets us force stop sidekiq independently 
  # of God.
  # w.pid_file = File.join(PROJECT_ROOT, 'tmp/pids/sidekiq.pid')
  w.log = "./log/god_sidekiq.log"
  w.behavior(:clean_pid_file)
end
4

1 回答 1

0

我也想知道控制启动顺序。我开始研究在 sidekiq 监视对象上使用监视转换方法并检查 redis 进程是否正在运行的可能性:可能通过 God.watches["redis"].state == :up 然后启动 sidekiq。时间用完了,只放了一个“sleep 5”;在 sidekiq 启动之前和 redis 关闭之前。

于 2013-03-29T15:57:20.543 回答