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
1717 recurring_tasks : [ ]
1818 }
1919
20- def initialize ( load_from : nil )
20+ def initialize ( mode : :fork , load_from : nil )
21+ @mode = mode . to_s . inquiry
2122 @raw_config = config_from ( load_from )
2223 end
2324
@@ -27,7 +28,11 @@ def processes
2728
2829 def workers
2930 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
3136 processes . times . map { Worker . new ( **worker_options . with_defaults ( WORKER_DEFAULTS ) ) }
3237 end
3338 end
@@ -45,7 +50,7 @@ def max_number_of_threads
4550 end
4651
4752 private
48- attr_reader :raw_config
53+ attr_reader :raw_config , :mode
4954
5055 DEFAULT_CONFIG_FILE_PATH = "config/solid_queue.yml"
5156
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class Supervisor < Processes::Base
77 class << self
88 def start ( mode : :fork , load_configuration_from : nil )
99 SolidQueue . supervisor = true
10- configuration = Configuration . new ( load_from : load_configuration_from )
10+ configuration = Configuration . new ( mode : mode , load_from : load_configuration_from )
1111
1212 klass = mode == :fork ? ForkSupervisor : AsyncSupervisor
1313 klass . new ( configuration ) . tap ( &:start )
Original file line number Diff line number Diff line change @@ -57,4 +57,14 @@ class ConfigurationTest < ActiveSupport::TestCase
5757 assert_equal [ "background" ] , configuration . workers . flat_map ( &:queues ) . uniq
5858 assert_equal [ 10 ] , configuration . workers . map ( &:polling_interval ) . uniq
5959 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
6070end
You can’t perform that action at this time.
0 commit comments