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