File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ class Configuration
17
17
recurring_tasks : [ ]
18
18
}
19
19
20
- def initialize ( load_from : nil )
20
+ def initialize ( mode : :fork , load_from : nil )
21
+ @mode = mode . to_s . inquiry
21
22
@raw_config = config_from ( load_from )
22
23
end
23
24
@@ -27,7 +28,11 @@ def processes
27
28
28
29
def workers
29
30
workers_options . flat_map do |worker_options |
30
- processes = worker_options . fetch ( :processes , WORKER_DEFAULTS [ :processes ] )
31
+ processes = if mode . fork?
32
+ worker_options . fetch ( :processes , WORKER_DEFAULTS [ :processes ] )
33
+ else
34
+ WORKER_DEFAULTS [ :processes ]
35
+ end
31
36
processes . times . map { Worker . new ( **worker_options . with_defaults ( WORKER_DEFAULTS ) ) }
32
37
end
33
38
end
@@ -45,7 +50,7 @@ def max_number_of_threads
45
50
end
46
51
47
52
private
48
- attr_reader :raw_config
53
+ attr_reader :raw_config , :mode
49
54
50
55
DEFAULT_CONFIG_FILE_PATH = "config/solid_queue.yml"
51
56
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class Supervisor < Processes::Base
7
7
class << self
8
8
def start ( mode : :fork , load_configuration_from : nil )
9
9
SolidQueue . supervisor = true
10
- configuration = Configuration . new ( load_from : load_configuration_from )
10
+ configuration = Configuration . new ( mode : mode , load_from : load_configuration_from )
11
11
12
12
klass = mode == :fork ? ForkSupervisor : AsyncSupervisor
13
13
klass . new ( configuration ) . tap ( &:start )
Original file line number Diff line number Diff line change @@ -57,4 +57,14 @@ class ConfigurationTest < ActiveSupport::TestCase
57
57
assert_equal [ "background" ] , configuration . workers . flat_map ( &:queues ) . uniq
58
58
assert_equal [ 10 ] , configuration . workers . map ( &:polling_interval ) . uniq
59
59
end
60
+
61
+ test "ignore processes option on async mode" do
62
+ background_worker = { queues : "background" , polling_interval : 10 , processes : 3 }
63
+ config_as_hash = { workers : [ background_worker ] }
64
+ configuration = SolidQueue ::Configuration . new ( mode : :async , load_from : config_as_hash )
65
+
66
+ assert_equal 1 , configuration . workers . count
67
+ assert_equal [ "background" ] , configuration . workers . first . queues
68
+ assert_equal 10 , configuration . workers . first . polling_interval
69
+ end
60
70
end
You can’t perform that action at this time.
0 commit comments