Skip to content

Commit

Permalink
Merge pull request #1 from MSPCFO/master
Browse files Browse the repository at this point in the history
Add support role specific configuration values seuros#158
  • Loading branch information
silentshade authored Mar 23, 2017
2 parents 339c42e + 5344c81 commit 0d3fec1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lib/capistrano/tasks/sidekiq.rake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ namespace :sidekiq do
end
end

def fetch_for_role(key)
host.roles.each do |role|
role_key = "#{role}_#{key.to_s.gsub('sidekiq_', '')}".to_sym
return fetch(role_key) if fetch(role_key)
end

return fetch(key)
end

def processes_pids
pids = []
sidekiq_roles = Array(fetch(:sidekiq_role))
Expand All @@ -63,13 +72,13 @@ namespace :sidekiq do

def stop_sidekiq(pid_file)
if fetch(:stop_sidekiq_in_background, fetch(:sidekiq_run_in_background))
if fetch(:sidekiq_use_signals)
if fetch_for_role(:sidekiq_use_signals)
background "kill -TERM `cat #{pid_file}`"
else
background :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
background :sidekiqctl, 'stop', "#{pid_file}", fetch_for_role(:sidekiq_timeout)
end
else
execute :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
execute :sidekiqctl, 'stop', "#{pid_file}", fetch_for_role(:sidekiq_timeout)
end
end

Expand All @@ -90,20 +99,20 @@ namespace :sidekiq do
args = []
args.push "--index #{idx}"
args.push "--pidfile #{pid_file}"
args.push "--environment #{fetch(:sidekiq_env)}"
args.push "--logfile #{fetch(:sidekiq_log)}" if fetch(:sidekiq_log)
args.push "--require #{fetch(:sidekiq_require)}" if fetch(:sidekiq_require)
args.push "--tag #{fetch(:sidekiq_tag)}" if fetch(:sidekiq_tag)
Array(fetch(:sidekiq_queue)).each do |queue|
args.push "--environment #{fetch_for_role(:sidekiq_env)}"
args.push "--logfile #{fetch_for_role(:sidekiq_log)}" if fetch_for_role(:sidekiq_log)
args.push "--require #{fetch_for_role(:sidekiq_require)}" if fetch_for_role(:sidekiq_require)
args.push "--tag #{fetch_for_role(:sidekiq_tag)}" if fetch_for_role(:sidekiq_tag)
Array(fetch_for_role(:sidekiq_queue)).each do |queue|
args.push "--queue #{queue}"
end
args.push "--config #{fetch(:sidekiq_config)}" if fetch(:sidekiq_config)
args.push "--concurrency #{fetch(:sidekiq_concurrency)}" if fetch(:sidekiq_concurrency)
if process_options = fetch(:sidekiq_options_per_process)
args.push "--config #{fetch_for_role(:sidekiq_config)}" if fetch_for_role(:sidekiq_config)
args.push "--concurrency #{fetch_for_role(:sidekiq_concurrency)}" if fetch_for_role(:sidekiq_concurrency)
if process_options = fetch_for_role(:sidekiq_options_per_process)
args.push process_options[idx]
end
# use sidekiq_options for special options
args.push fetch(:sidekiq_options) if fetch(:sidekiq_options)
args.push fetch_for_role(:sidekiq_options) if fetch_for_role(:sidekiq_options)

if defined?(JRUBY_VERSION)
args.push '>/dev/null 2>&1 &'
Expand Down

0 comments on commit 0d3fec1

Please sign in to comment.