Skip to content

Commit 9cc6f93

Browse files
committed
Don't raise if there's no config file in the default location
Use the defaults in that case.
1 parent 224bbfa commit 9cc6f93

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

lib/solid_queue/configuration.rb

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,37 @@ def dispatchers_options
7373
.map { |options| options.dup.symbolize_keys }
7474
end
7575

76+
7677
def load_config_from(file_or_hash)
7778
case file_or_hash
78-
when Pathname then load_config_file file_or_hash
79-
when String then load_config_file Pathname.new(file_or_hash)
80-
when NilClass then load_config_file default_config_file
81-
when Hash then file_or_hash.dup
82-
else raise "Solid Queue cannot be initialized with #{file_or_hash.inspect}"
79+
when Hash
80+
file_or_hash.dup
81+
when Pathname, String
82+
load_config_from_file Pathname.new(file_or_hash)
83+
when NilClass
84+
load_config_from_env_location || load_config_from_default_location
85+
else
86+
raise "Solid Queue cannot be initialized with #{file_or_hash.inspect}"
8387
end
8488
end
8589

86-
def load_config_file(file)
87-
if file.exist?
88-
ActiveSupport::ConfigurationFile.parse(file).deep_symbolize_keys
89-
else
90-
raise "Configuration file not found in #{file}"
90+
def load_config_from_env_location
91+
if ENV["SOLID_QUEUE_CONFIG"].present?
92+
load_config_from_file Rails.root.join(ENV["SOLID_QUEUE_CONFIG"])
9193
end
9294
end
9395

94-
def default_config_file
95-
path_to_file = ENV["SOLID_QUEUE_CONFIG"] || DEFAULT_CONFIG_FILE_PATH
96+
def load_config_from_default_location
97+
Rails.root.join(DEFAULT_CONFIG_FILE_PATH).then do |config_file|
98+
config_file.exist? ? load_config_from_file(config_file) : {}
99+
end
100+
end
96101

97-
Rails.root.join(path_to_file).tap do |config_file|
98-
raise "Configuration for Solid Queue not found in #{config_file}" unless config_file.exist?
102+
def load_config_from_file(file)
103+
if file.exist?
104+
ActiveSupport::ConfigurationFile.parse(file).deep_symbolize_keys
105+
else
106+
raise "Configuration file for Solid Queue not found in #{file}"
99107
end
100108
end
101109
end

test/unit/configuration_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
class ConfigurationTest < ActiveSupport::TestCase
44
test "default configuration to process all queues and dispatch" do
5-
configuration = SolidQueue::Configuration.new(mode: :all, load_from: {})
5+
configuration = stub_const(SolidQueue::Configuration, :DEFAULT_CONFIG_FILE_PATH, "non/existent/path") do
6+
SolidQueue::Configuration.new(mode: :all)
7+
end
8+
69
assert_equal 2, configuration.processes.count
710

811
assert_equal 1, configuration.workers.count

0 commit comments

Comments
 (0)