Skip to content
代码片段 群组 项目
提交 dc81976d 编辑于 作者: Oswaldo Ferreira's avatar Oswaldo Ferreira
浏览文件

Use --negate as a flag without arguments

上级 60f21ff9
No related branches found
No related tags found
无相关合并请求
...@@ -30,14 +30,16 @@ def run(argv = ARGV) ...@@ -30,14 +30,16 @@ def run(argv = ARGV)
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 @@ def option_parser ...@@ -99,8 +101,8 @@ def option_parser
@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 @@ ...@@ -20,17 +20,17 @@
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
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册