Commit 37413133 by zmj

添加god

parent 4719fa57
......@@ -74,4 +74,5 @@ gem 'settingslogic', '~> 2.0', '>= 2.0.9'
gem 'httparty', '~> 0.13.7'
gem 'redis-rails', '~> 5.0', '>= 5.0.2'
gem 'rails_param', '~> 0.10.2'
gem 'sidekiq', '~> 4.1', '>= 4.1.2'
\ No newline at end of file
gem 'sidekiq', '~> 4.1', '>= 4.1.2'
gem 'god', '~> 0.13.7'
\ No newline at end of file
......@@ -102,6 +102,7 @@ GEM
ffi (1.11.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
god (0.13.7)
httparty (0.13.7)
json (~> 1.8)
multi_xml (>= 0.5.2)
......@@ -266,6 +267,7 @@ DEPENDENCIES
capybara (>= 2.15)
chromedriver-helper
coffee-rails (~> 4.2)
god (~> 0.13.7)
httparty (~> 0.13.7)
igetui-ruby
jbuilder (~> 2.5)
......
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
QUEUES = {
push: { concurrency: 10, workers: 2, memory: 1000 }
}
pid_index = 0
QUEUES.each { |queue_name, queue_conf|
sidekiq_log_file = "#{APP_ROOT}/log/sidekiq-#{queue_name}.log"
queue_conf[:workers].times {
sidekiq_pid_file = "#{APP_ROOT}/tmp/pids/sidekiq-#{queue_name}-#{pid_index}.pid"
God.watch do |w|
w.env = {
"APP_ROOT" => "#{APP_ROOT}",
"BUNDLE_GEMFILE" => "#{APP_ROOT}/Gemfile",
"APP_MEMORY" => queue_conf[:memory]
}
w.dir = APP_ROOT
w.log = sidekiq_log_file
w.interval = 30.seconds
w.name = "ikcrm_operating_sidekiq_#{queue_name}-#{pid_index}"
w.group = "ikcrm_operating_sidekiq"
w.start = "cd #{APP_ROOT}; DB_USE_SLAVE=#{!!(queue_name.to_s =~ /slave/)} DB_POOL_SIZE=#{queue_conf[:concurrency] + 2} nohup bundle exec sidekiq -C config/sidekiq.yml -c #{queue_conf[:concurrency]} -e production --queue #{queue_name},#{queue_conf[:priority]} -i #{pid_index} -P #{sidekiq_pid_file} >> #{sidekiq_log_file} 2>&1 &"
w.stop = "if [ -d #{APP_ROOT} ] && [ -f #{sidekiq_pid_file} ] && kill -0 `cat #{sidekiq_pid_file}`> /dev/null 2>&1; then cd #{APP_ROOT} && bundle exec sidekiqctl stop #{sidekiq_pid_file} 10 ; else echo 'Sidekiq is not running'; fi"
w.pid_file = sidekiq_pid_file
w.behavior(:clean_pid_file)
w.start_grace = 10.seconds
w.restart_grace = 5.minutes
w.stop_timeout = 5.minutes
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.minutes
c.running = false
end
end
w.lifecycle do |on|
on.condition(:flapping) do |c|
c.to_state = [:start, :restart]
c.times = 3
c.within = 5.minute
c.transition = :unmonitored
c.retry_in = 10.minutes
c.retry_times = 2
c.retry_within = 2.hours
end
end
memory_size = queue_conf[:memory].to_i
w.keepalive(memory_max: memory_size.megabytes)
end
pid_index += 1
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment