Skip to content

Commit

Permalink
Merge pull request #686 from csebryam/load-rails-earlier
Browse files Browse the repository at this point in the history
Initialize Rails before parsing Config File
  • Loading branch information
cjlarose authored Jan 20, 2022
2 parents 155c97a + dfa286d commit 73edd23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/shoryuken/environment_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def initialize(options)
end

def setup_options
initialize_rails if load_rails?
initialize_options
initialize_logger
end

def load
load_rails if Shoryuken.options[:rails]
prefix_active_job_queue_names
parse_queues
require_workers
Expand Down Expand Up @@ -55,7 +55,7 @@ def initialize_logger
Shoryuken.logger.level = Logger::DEBUG if Shoryuken.options[:verbose]
end

def load_rails
def initialize_rails
# Adapted from: https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/cli.rb

require 'rails'
Expand All @@ -79,6 +79,10 @@ def load_rails
end
end

def load_rails?
options[:rails]
end

def prefix_active_job_queue_name(queue_name, weight)
return [queue_name, weight] if queue_name.start_with?('https://', 'arn:')

Expand Down
3 changes: 0 additions & 3 deletions lib/shoryuken/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def run(options)

loader = EnvironmentLoader.setup_options(options)

# When cli args exist, override options in config file
Shoryuken.options.merge!(options)

daemonize(Shoryuken.options)
write_pid(Shoryuken.options)

Expand Down
6 changes: 3 additions & 3 deletions spec/shoryuken/environment_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

describe '#parse_queues loads default queues' do
before do
allow(subject).to receive(:load_rails)
allow(subject).to receive(:initialize_rails)
allow(subject).to receive(:prefix_active_job_queue_names)
allow(subject).to receive(:require_workers)
allow(subject).to receive(:validate_queues)
Expand All @@ -54,7 +54,7 @@

describe '#parse_queues includes delay per groups' do
before do
allow(subject).to receive(:load_rails)
allow(subject).to receive(:initialize_rails)
allow(subject).to receive(:prefix_active_job_queue_names)
allow(subject).to receive(:require_workers)
allow(subject).to receive(:validate_queues)
Expand All @@ -76,7 +76,7 @@

describe '#prefix_active_job_queue_names' do
before do
allow(subject).to receive(:load_rails)
allow(subject).to receive(:initialize_rails)
allow(subject).to receive(:require_workers)
allow(subject).to receive(:validate_queues)
allow(subject).to receive(:validate_workers)
Expand Down

0 comments on commit 73edd23

Please sign in to comment.