Commit 59e19c49 authored by Nick Thomas's avatar Nick Thomas

sidekiq-cluster: put each sidekiq in a new pgroup

We now kill the whole process group for termination signals
parent 6abfc790
---
title: 'sidekiq-cluster: put each sidekiq in a new pgroup'
merge_request: 9775
author:
type: other
...@@ -56,7 +56,7 @@ module Gitlab ...@@ -56,7 +56,7 @@ module Gitlab
# start([ ['foo'], ['bar', 'baz'] ], :production) # start([ ['foo'], ['bar', 'baz'] ], :production)
# #
# This would start two Sidekiq processes: one processing "foo", and one # This would start two Sidekiq processes: one processing "foo", and one
# processing "bar" and "baz". # processing "bar" and "baz". Each one is placed in its own process group.
# #
# queues - An Array containing Arrays. Each sub Array should specify the # queues - An Array containing Arrays. Each sub Array should specify the
# queues to use for a single process. # queues to use for a single process.
...@@ -92,6 +92,7 @@ module Gitlab ...@@ -92,6 +92,7 @@ module Gitlab
pid = Process.spawn( pid = Process.spawn(
{ 'ENABLE_SIDEKIQ_CLUSTER' => '1' }, { 'ENABLE_SIDEKIQ_CLUSTER' => '1' },
*cmd, *cmd,
pgroup: true,
err: $stderr, err: $stderr,
out: $stdout out: $stdout
) )
......
...@@ -79,6 +79,7 @@ describe Gitlab::SidekiqCluster do ...@@ -79,6 +79,7 @@ describe Gitlab::SidekiqCluster do
describe '.start_sidekiq' do describe '.start_sidekiq' do
let(:env) { { "ENABLE_SIDEKIQ_CLUSTER" => "1" } } let(:env) { { "ENABLE_SIDEKIQ_CLUSTER" => "1" } }
let(:args) { ['bundle', 'exec', 'sidekiq', anything, '-eproduction', *([anything] * 5)] }
it 'starts a Sidekiq process' do it 'starts a Sidekiq process' do
allow(Process).to receive(:spawn).and_return(1) allow(Process).to receive(:spawn).and_return(1)
...@@ -88,13 +89,24 @@ describe Gitlab::SidekiqCluster do ...@@ -88,13 +89,24 @@ describe Gitlab::SidekiqCluster do
end end
it 'handles duplicate queue names' do it 'handles duplicate queue names' do
allow(Process).to receive(:spawn) allow(Process)
.with(env, "bundle", "exec", "sidekiq", "-c 5", "-eproduction", "-gqueues: foo (2), bar, baz", anything, "-qfoo,2", "-qbar,1", "-qbaz,1", anything) .to receive(:spawn)
.with(env, *args, anything)
.and_return(1) .and_return(1)
expect(described_class).to receive(:wait_async).with(1) expect(described_class).to receive(:wait_async).with(1)
expect(described_class.start_sidekiq(%w(foo foo bar baz), :production)).to eq(1) expect(described_class.start_sidekiq(%w(foo foo bar baz), :production)).to eq(1)
end end
it 'runs the sidekiq process in a new process group' do
expect(Process)
.to receive(:spawn)
.with(anything, *args, a_hash_including(pgroup: true))
.and_return(1)
allow(described_class).to receive(:wait_async)
expect(described_class.start_sidekiq(%w(foo bar baz), :production)).to eq(1)
end
end end
describe '.wait_async' do describe '.wait_async' do
......
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