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

Support different queues per role #85

Open
wants to merge 1 commit 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
21 changes: 13 additions & 8 deletions lib/capistrano/tasks/sidekiq.cap
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ namespace :sidekiq do
end
end

def start_sidekiq(pid_file, idx = 0)
def start_sidekiq(pid_file, host, idx = 0)
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|
Array(queue_for_host(host)).each do |queue|
args.push "--queue #{queue}"
end
args.push "--config #{fetch(:sidekiq_config)}" if fetch(:sidekiq_config)
Expand All @@ -120,6 +120,11 @@ namespace :sidekiq do
end
end

def queue_for_host(host)
sidekiq_roles = host.roles & fetch(:sidekiq_role)
fetch(:"#{ sidekiq_roles.first }_queue") || fetch(:sidekiq_queue)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only thing I don't like here, it's possible you could have a host with more than one sidekiq role, in which case I'm just arbitrarily selecting the first one... Do you think that should raise an error instead?

end

task :add_default_hooks do
after 'deploy:starting', 'sidekiq:quiet'
after 'deploy:updated', 'sidekiq:stop'
Expand Down Expand Up @@ -155,9 +160,9 @@ namespace :sidekiq do

desc 'Start sidekiq'
task :start do
on roles fetch(:sidekiq_role) do
on roles fetch(:sidekiq_role) do |host|
for_each_process do |pid_file, idx|
start_sidekiq(pid_file, idx) unless pid_process_exists?(pid_file)
start_sidekiq(pid_file, host, idx) unless pid_process_exists?(pid_file)
end
end
end
Expand All @@ -170,12 +175,12 @@ namespace :sidekiq do

desc 'Rolling-restart sidekiq'
task :rolling_restart do
on roles fetch(:sidekiq_role) do
on roles fetch(:sidekiq_role) do |host|
for_each_process(true) do |pid_file, idx|
if pid_process_exists?(pid_file)
stop_sidekiq(pid_file)
end
start_sidekiq(pid_file, idx)
start_sidekiq(pid_file, host, idx)
end
end
end
Expand All @@ -195,10 +200,10 @@ namespace :sidekiq do
desc 'Respawn missing sidekiq processes'
task :respawn do
invoke 'sidekiq:cleanup'
on roles fetch(:sidekiq_role) do
on roles fetch(:sidekiq_role) do |host|
for_each_process do |pid_file, idx|
unless pid_file_exists?(pid_file)
start_sidekiq(pid_file, idx)
start_sidekiq(pid_file, host, idx)
end
end
end
Expand Down