Skip to content

Commit 8c42242

Browse files
committed
Default to a single worker with default settings when no config is provided
In this way, someone just starting Solid Queue will have something that dispatches and processes jobs without having to worry about a configuration file. Also: make the default queues (all queues) explicit.
1 parent 816c6a8 commit 8c42242

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/solid_queue/configuration.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
module SolidQueue
44
class Configuration
55
WORKER_DEFAULTS = {
6+
queues: "*",
67
threads: 5,
78
processes: 1,
89
polling_interval: 0.1
910
}
1011

1112
DISPATCHER_DEFAULTS = {
1213
batch_size: 500,
13-
polling_interval: 5,
14+
polling_interval: 1,
1415
concurrency_maintenance_interval: 600
1516
}
1617

@@ -61,7 +62,7 @@ def config_from(file_or_hash, env: Rails.env)
6162
end
6263

6364
def workers_options
64-
@workers_options ||= (raw_config[:workers] || {}).map { |options| options.dup.symbolize_keys }
65+
@workers_options ||= (raw_config[:workers] || [ WORKER_DEFAULTS ]).map { |options| options.dup.symbolize_keys }
6566
end
6667

6768
def dispatcher_options

test/unit/configuration_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
require "test_helper"
22

33
class ConfigurationTest < ActiveSupport::TestCase
4+
test "default configuration to process all queues and dispatch" do
5+
configuration = SolidQueue::Configuration.new(mode: :all, load_from: {})
6+
assert_equal 2, configuration.processes.count
7+
8+
assert_equal 1, configuration.workers.count
9+
assert configuration.dispatcher.present?
10+
11+
assert_equal [ "*" ], configuration.workers.first.queues
12+
assert_equal SolidQueue::Configuration::DISPATCHER_DEFAULTS[:batch_size], configuration.dispatcher.batch_size
13+
end
14+
415
test "read configuration from default file" do
516
configuration = SolidQueue::Configuration.new(mode: :all)
617
assert 3, configuration.processes.count

0 commit comments

Comments
 (0)