Skip to content

Commit 0459dfd

Browse files
committed
Allow non-rails workers to access more settings
1 parent 26d321d commit 0459dfd

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

app/models/miq_worker.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ def self.concrete_subclasses
9090
leaf_subclasses | descendants.select { |d| d.try(:acts_as_sti_leaf_class?) }
9191
end
9292

93-
class_attribute :default_queue_name, :required_roles, :maximum_workers_count, :include_stopping_workers_on_synchronize
93+
class_attribute :default_queue_name, :required_roles, :maximum_workers_count, :include_stopping_workers_on_synchronize, :worker_settings_paths
9494
self.include_stopping_workers_on_synchronize = false
9595
self.required_roles = []
96+
self.worker_settings_paths = []
9697

9798
def self.server_scope
9899
return current_scope if current_scope && current_scope.where_values_hash.include?('miq_server_id')
@@ -225,7 +226,9 @@ def self.fetch_worker_settings_from_options_hash(options_hash, raw = false)
225226
# and decrypt any values which are encrypted with ManageIQ::Password.
226227
def self.normalize_settings!(settings)
227228
settings.each_key do |k|
228-
if settings[k].kind_of?(String)
229+
if settings[k].kind_of?(Hash)
230+
normalize_settings!(settings[k])
231+
elsif settings[k].kind_of?(String)
229232
if settings[k].number_with_method?
230233
settings[k] = settings[k].to_i_with_method
231234
elsif settings[k].match?(/\A\d+(.\d+)?\z/) # case where int/float saved as string
@@ -236,7 +239,6 @@ def self.normalize_settings!(settings)
236239
end
237240
end
238241
end
239-
private_class_method :normalize_settings!
240242

241243
def worker_settings(options = {})
242244
self.class.fetch_worker_settings_from_server(miq_server, options)

app/models/miq_worker/runner.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,17 @@ def set_process_title
485485
private
486486

487487
def worker_options
488+
settings = {
489+
:worker_settings => worker_settings
490+
}
491+
492+
worker.class.worker_settings_paths.to_a.each do |settings_path|
493+
settings.store_path(settings_path, Settings.to_hash.dig(*settings_path))
494+
end
495+
488496
{
489497
:messaging => MiqQueue.messaging_client_options,
490-
:settings => worker_settings.to_hash
498+
:settings => worker.class.normalize_settings!(settings)
491499
}
492500
end
493501

0 commit comments

Comments
 (0)