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
# queues - An Array containing Arrays. Each sub Array should specify the
# queues to use for a single process.
#
# directory - The directory of the Rails application.
#
# Returns an Array containing the PIDs of the started processes.
def self.start(queues, env)
queues.map { |pair| start_sidekiq(pair, env) }
def self.start(queues, env, directory = Dir.pwd)
queues.map { |pair| start_sidekiq(pair, env, directory) }
end
# Starts a Sidekiq process that processes _only_ the given queues.
#
# 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" }
pid = Process.spawn(
......
......@@ -14,6 +14,7 @@ module Gitlab
@alive = true
@processes = []
@logger = Logger.new(log_output)
@rails_path = Dir.pwd
# Use a log format similar to Sidekiq to make parsing/grepping easier.
@logger.formatter = proc do |level, date, program, message|
......@@ -33,7 +34,7 @@ module Gitlab
@logger.info("Starting cluster with #{queues.length} processes")
@processes = SidekiqCluster.start(queues, @environment)
@processes = SidekiqCluster.start(queues, @environment, @rails_path)
write_pid
trap_signals
......@@ -88,6 +89,10 @@ module Gitlab
@pid = pid
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|
@interval = int.to_i
end
......
......@@ -58,12 +58,12 @@ describe Gitlab::SidekiqCluster do
describe '.start' do
it 'starts Sidekiq with the given queues and environment' do
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).
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
......
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