Commit dc81976d authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Use --negate as a flag without arguments

parent 60f21ff9
......@@ -30,14 +30,16 @@ module Gitlab
option_parser.parse!(argv)
parsed_queues = SidekiqCluster.parse_queues(argv)
queues =
if @negated_queues&.any?
parsed_queues = SidekiqCluster.parse_queues(@negated_queues)
if @negate_queues
parsed_queues.map { |queues| SidekiqConfig.queues(@rails_path, except: queues) }
else
SidekiqCluster.parse_queues(argv)
parsed_queues
end
@logger.info("Starting cluster with #{queues.length} processes")
@processes = SidekiqCluster.start(queues, @environment, @rails_path)
......@@ -99,8 +101,8 @@ module Gitlab
@rails_path = path
end
opt.on('-n', '--negate "[QUEUE,QUEUE] [QUEUE]"', "Run workers for all queues except these") do |queues|
@negated_queues = queues.split
opt.on('-n', '--negate', 'Run workers for all queues on sidekiq_queues.yml except the given ones') do
@negate_queues = true
end
opt.on('-i', '--interval INT', 'The number of seconds to wait between worker checks') do |int|
......
......@@ -20,17 +20,17 @@ describe Gitlab::SidekiqCluster::CLI do
cli.run(%w(foo))
end
context 'with --negate argument' do
it 'starts Sidekiq workers for all queues except the negated ones' do
expect(Gitlab::SidekiqConfig).to receive(:queues).twice.and_return(['baz'])
context 'with --negate flag' do
it 'starts Sidekiq workers for all queues on sidekiq_queues.yml except the ones on argv' do
expect(Gitlab::SidekiqConfig).to receive(:queues).and_return(['baz'])
expect(Gitlab::SidekiqCluster).to receive(:start)
.with([['baz'], ['baz']], 'test', Dir.pwd)
.with([['baz']], 'test', Dir.pwd)
.and_return([])
expect(cli).to receive(:write_pid)
expect(cli).to receive(:trap_signals)
expect(cli).to receive(:start_loop)
cli.run(['-n', 'foo,bar foo,bar'])
cli.run(%w(foo -n))
end
end
end
......
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