Skip to content

Commit

Permalink
Eager load api collection classes in ui workers
Browse files Browse the repository at this point in the history
Similar change but now for the UI worker:
ManageIQ#20072

"Allowing threads to autoload code requires us to spend time tracking down bugs
in code loading and insert disgusting rails interlock blocks to "protect"
various places that could load constants in threads.

This solution tries to avoid these workarounds by eager loading all of the
collection classes and their descendants before any requests are made, since
we're likely to need to load them anyway."

Note, the api classes from the manageiq-api repo is included in the manageiq_default
gemset, so it's safe to use it.

Note, web console worker is another web server worker, so we're only doing UI here
in addition to the web service worker we did previously, but we're not doing it for
all web server workers.
  • Loading branch information
jrafanie committed Nov 10, 2020
1 parent 0f05bac commit 334fee0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/miq_ui_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def self.kill_priority
MiqWorkerType::KILL_PRIORITY_UI_WORKERS
end

def self.preload_for_worker_role
super
Api::ApiConfig.collections.each { |_k, v| v.klass.try(:constantize).try(:descendants) }
end

def container_port
3001
end
Expand Down
7 changes: 7 additions & 0 deletions spec/models/miq_ui_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@
expect(described_class.reserve_port(ports)).to eq(3001)
end
end

it "#preload_for_worker_role autoloads api collection classes and descendants" do
allow(EvmDatabase).to receive(:seeded_primordially?).and_return(true)
expect(MiqUiWorker).to receive(:configure_secret_token)
MiqUiWorker.preload_for_worker_role
expect(defined?(ServiceAnsibleTower)).to be_truthy
end
end

0 comments on commit 334fee0

Please sign in to comment.