Commit 765e7f1a authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch 'add-list-queues-to-sidekiq-cluster' into 'master'

Add --list-queues option to sidekiq-cluster

See merge request gitlab-org/gitlab!66474
parents 616ad664 c591bf77
......@@ -37,6 +37,7 @@ module Gitlab
@logger.formatter = ::Gitlab::SidekiqLogging::JSONFormatter.new
@rails_path = Dir.pwd
@dryrun = false
@list_queues = false
end
def run(argv = ARGV)
......@@ -47,6 +48,11 @@ module Gitlab
option_parser.parse!(argv)
if @dryrun && @list_queues
raise CommandError,
'The --dryrun and --list-queues options are mutually exclusive'
end
worker_metadatas = SidekiqConfig::CliMethods.worker_metadatas(@rails_path)
worker_queues = SidekiqConfig::CliMethods.worker_queues(@rails_path)
......@@ -73,6 +79,12 @@ module Gitlab
'No queues found, you must select at least one queue'
end
if @list_queues
puts queue_groups.map(&:sort) # rubocop:disable Rails/Output
return
end
unless @dryrun
@logger.info("Starting cluster with #{queue_groups.length} processes")
end
......@@ -202,6 +214,10 @@ module Gitlab
opt.on('-d', '--dryrun', 'Print commands that would be run without this flag, and quit') do |int|
@dryrun = true
end
opt.on('--list-queues', 'List matching queues, and quit') do |int|
@list_queues = true
end
end
end
end
......
......@@ -81,7 +81,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do
end
end
context '-timeout flag' do
context 'with --timeout flag' do
it 'when given', 'starts Sidekiq workers with given timeout' do
expect(Gitlab::SidekiqCluster).to receive(:start)
.with([['foo']], default_options.merge(timeout: 10))
......@@ -97,6 +97,27 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do
end
end
context 'with --list-queues flag' do
it 'errors when given --list-queues and --dryrun' do
expect { cli.run(%w(foo --list-queues --dryrun)) }.to raise_error(described_class::CommandError)
end
it 'prints out a list of queues in alphabetical order' do
expected_queues = [
'epics:epics_update_epics_dates',
'epics_new_epic_issue',
'new_epic',
'todos_destroyer:todos_destroyer_confidential_epic'
]
allow(Gitlab::SidekiqConfig::CliMethods).to receive(:query_queues).and_return(expected_queues.shuffle)
expect(cli).to receive(:puts).with([expected_queues])
cli.run(%w(--queue-selector feature_category=epics --list-queues))
end
end
context 'queue namespace expansion' do
it 'starts Sidekiq workers for all queues in all_queues.yml with a namespace in argv' do
expect(Gitlab::SidekiqConfig::CliMethods).to receive(:worker_queues).and_return(['cronjob:foo', 'cronjob:bar'])
......
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