Skip to content

Commit 057977b

Browse files
committed
Use default worker/dispatcher only when the configuration is empty
That is, if there is some configuration not empty, do not fill missing dispatcher or worker with the default. Just assume no working/dispatching.
1 parent 16d32cb commit 057977b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/solid_queue/configuration.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,19 @@ def config_from(file_or_hash, env: Rails.env)
5555
end
5656

5757
def workers_options
58-
@workers_options ||= (raw_config[:workers] || [ WORKER_DEFAULTS ])
58+
@workers_options ||= options_from_raw_config(:workers, WORKER_DEFAULTS)
5959
.map { |options| options.dup.symbolize_keys }
6060
end
6161

6262
def dispatchers_options
63-
@dispatchers_options ||= (raw_config[:dispatchers] || [ DISPATCHER_DEFAULTS ])
63+
@dispatchers_options ||= options_from_raw_config(:dispatchers, DISPATCHER_DEFAULTS)
6464
.map { |options| options.dup.symbolize_keys }
6565
end
6666

67+
def options_from_raw_config(key, defaults)
68+
raw_config.empty? ? [ defaults ] : Array(raw_config[key])
69+
end
70+
6771
def parse_recurring_tasks(tasks)
6872
Array(tasks).map do |id, options|
6973
Dispatcher::RecurringTask.from_configuration(id, **options)

test/unit/configuration_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class ConfigurationTest < ActiveSupport::TestCase
3636
assert_equal 2, configuration.workers.count
3737
assert_equal [ "background" ], configuration.workers.flat_map(&:queues).uniq
3838
assert_equal [ 10 ], configuration.workers.map(&:polling_interval).uniq
39+
40+
config_as_hash = { workers: [ background_worker, background_worker ] }
41+
configuration = SolidQueue::Configuration.new(load_from: config_as_hash)
42+
assert_empty configuration.dispatchers
43+
assert_equal 2, configuration.workers.count
3944
end
4045

4146
test "max number of threads" do

0 commit comments

Comments
 (0)