Commit 003d04f4 authored by Yorick Peterse's avatar Yorick Peterse

Support require directory for sidekiq-cluster

sidekiq-cluster now supports the same -r/--require option as Sidekiq
itself does. This is needed as Omnibus changes the working directory,
preventing us from properly starting the sidekiq processes.
parent 70a4e8dc
...@@ -59,15 +59,17 @@ module Gitlab ...@@ -59,15 +59,17 @@ module Gitlab
# 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.
# #
# directory - The directory of the Rails application.
#
# Returns an Array containing the PIDs of the started processes. # Returns an Array containing the PIDs of the started processes.
def self.start(queues, env) def self.start(queues, env, directory = Dir.pwd)
queues.map { |pair| start_sidekiq(pair, env) } queues.map { |pair| start_sidekiq(pair, env, directory) }
end end
# Starts a Sidekiq process that processes _only_ the given queues. # Starts a Sidekiq process that processes _only_ the given queues.
# #
# Returns the PID of the started process. # Returns the PID of the started process.
def self.start_sidekiq(queues, env) def self.start_sidekiq(queues, env, directory = Dir.pwd)
switches = queues.map { |q| "-q #{q},1" } switches = queues.map { |q| "-q #{q},1" }
pid = Process.spawn( pid = Process.spawn(
......
...@@ -14,6 +14,7 @@ module Gitlab ...@@ -14,6 +14,7 @@ module Gitlab
@alive = true @alive = true
@processes = [] @processes = []
@logger = Logger.new(log_output) @logger = Logger.new(log_output)
@rails_path = Dir.pwd
# Use a log format similar to Sidekiq to make parsing/grepping easier. # Use a log format similar to Sidekiq to make parsing/grepping easier.
@logger.formatter = proc do |level, date, program, message| @logger.formatter = proc do |level, date, program, message|
...@@ -33,7 +34,7 @@ module Gitlab ...@@ -33,7 +34,7 @@ module Gitlab
@logger.info("Starting cluster with #{queues.length} processes") @logger.info("Starting cluster with #{queues.length} processes")
@processes = SidekiqCluster.start(queues, @environment) @processes = SidekiqCluster.start(queues, @environment, @rails_path)
write_pid write_pid
trap_signals trap_signals
...@@ -88,6 +89,10 @@ module Gitlab ...@@ -88,6 +89,10 @@ module Gitlab
@pid = pid @pid = pid
end end
opt.on('-r', '--require PATH', 'Location of the Rails application') do |path|
@rails_path = path
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|
@interval = int.to_i @interval = int.to_i
end end
......
...@@ -58,12 +58,12 @@ describe Gitlab::SidekiqCluster do ...@@ -58,12 +58,12 @@ describe Gitlab::SidekiqCluster do
describe '.start' do describe '.start' do
it 'starts Sidekiq with the given queues and environment' do it 'starts Sidekiq with the given queues and environment' do
expect(described_class).to receive(:start_sidekiq). expect(described_class).to receive(:start_sidekiq).
ordered.with(%w(foo), :production) ordered.with(%w(foo), :production, 'foo/bar')
expect(described_class).to receive(:start_sidekiq). expect(described_class).to receive(:start_sidekiq).
ordered.with(%w(bar baz), :production) ordered.with(%w(bar baz), :production, 'foo/bar')
described_class.start([%w(foo), %w(bar baz)], :production) described_class.start([%w(foo), %w(bar baz)], :production, 'foo/bar')
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