-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Use zeitwerk on load instead of hooking descendants subclasses #22945
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,27 @@ | |
Rails.autoloaders.main.collapse(Rails.root.join("lib/manageiq/reporting/charting")) | ||
Rails.autoloaders.main.collapse(Rails.root.join("lib/ansible/runner/credential")) | ||
Rails.autoloaders.main.collapse(Rails.root.join("lib/pdf_generator")) | ||
|
||
excluded_from_eager_load = %w[ | ||
ApplicationRecord | ||
MiqDecorator | ||
OrchestrationStack::Status | ||
ResourcePool | ||
] | ||
|
||
DescendantLoader.instance.discovered_parent_child_classes.each do |parent, children| | ||
next if excluded_from_eager_load.include?(parent) | ||
|
||
puts "Registering on_load for class: #{parent}" | ||
Rails.autoloaders.main.on_load(parent.to_s) do |klass, _abspath| | ||
puts "Running on_load for class: #{klass} with children: #{children}" | ||
children.each do |child| | ||
begin | ||
child.safe_constantize | ||
rescue NameError => err | ||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can safe_constantize actually raise a NameError? I thought under the covers they caught that and just returned nil. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it actually did, thanks for reminding me. I need to investigate why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the short of it is that some top level classes can introduce cycles if you try to constantize their children. Their children can reference constants that get loaded and loading of mixins and perent classes and some of those kick off more constantizing of children classes and some of those can be cyclic loads. So far, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ewwww ResourcePool is bad. We need to fix that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I'm getting things green with the current code and will try to figure out how to fix these classes or fix how we load. |
||
puts "!!! FAILED to load #{child} for parent: #{klass} with inheritance column: #{klass.try(:inheritance_column)} reason: #{err}. Error class: #{err.class.name}" | ||
raise | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is for debug but I wonder if we should keep it and use $log.debug instead. (Same comment for the other puts lines)