Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support role specific configuration values #158

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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