-
Notifications
You must be signed in to change notification settings - Fork 900
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
Cleanup constantize of worker_class_names #21470
Changes from 1 commit
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 |
---|---|---|
|
@@ -40,21 +40,14 @@ def worker_not_responding(w) | |
end | ||
|
||
def sync_workers | ||
result = {} | ||
MiqWorkerType.worker_class_names.each do |class_name| | ||
begin | ||
c = class_name.constantize | ||
raise NameError, "Constant problem: expected: #{class_name}, constantized: #{c.name}" unless c.name == class_name | ||
|
||
result[c.name] = c.sync_workers | ||
result[c.name][:adds].each { |pid| worker_add(pid) unless pid.nil? } | ||
rescue => error | ||
agrare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_log.error("Failed to sync_workers for class: #{class_name}") | ||
_log.log_backtrace(error) | ||
next | ||
end | ||
MiqWorkerType.worker_class_names.map(&:constantize).each_with_object({}) do |klass, result| | ||
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. Wondering if 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. 💯 may or may not already have that branch as a follow-up to this :) 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. doing a search in the core repo shows $ git grep worker_class_names
app/models/miq_server/worker_management/monitor.rb:44: MiqWorkerType.worker_class_names.each do |class_name|
app/models/miq_server/worker_management/monitor.rb:163: MiqWorkerType.worker_class_names_in_kill_order.each do |class_name|
app/models/miq_server/worker_management/monitor/settings.rb:11: MiqWorkerType.worker_class_names.each do |class_name|
app/models/miq_server/worker_management/monitor/start.rb:13: starting = MiqWorker.find_starting.find_all { |w| MiqWorkerType.worker_class_names.include?(w.class.name)
app/models/miq_server/worker_management/monitor/systemd.rb:51: MiqWorkerType.worker_class_names.map(&:constantize).map(&:service_base_name)
app/models/miq_worker_type.rb:27: def self.worker_class_names
app/models/miq_worker_type.rb:31: def self.worker_class_names_in_kill_order
spec/models/miq_server/worker_management/monitor_spec.rb:99: allow(MiqWorkerType).to receive(:worker_class_names).and_return(%w[ManageIQ::Providers::Foreman::Provis
spec/models/miq_server/worker_management/monitor_spec.rb:107: allow(MiqWorkerType).to receive(:worker_class_names).and_return(%w(MiqGenericWorker MiqPriorityWorker)
spec/models/miq_server/worker_management/monitor_spec.rb:114: allow(MiqWorkerType).to receive(:worker_class_names).and_return([])
spec/models/miq_worker/systemd_common_spec.rb:10: found_units = MiqWorkerType.worker_class_names.flat_map do |klass_name| I would bet that each of those callers is doing a 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 not all of them are but the majority 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. Note, I can look to see if that's still an issue. But here's more context: #19400 (comment) 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. Right AFAIK constantizing classes which don't exist won't always fail (could resolve to the non-namespaced base class), but constantizing classes which do exist will always resolve to the right thing? 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. @agrare I believe that's correct. 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. Note that newer versions of Ruby / Rails may have eliminated this problem entirely as well, but in this case you know all the values will exist (because they were derived from existing values), so you are safe. |
||
result[klass.name] = klass.sync_workers | ||
result[klass.name][:adds].each { |pid| worker_add(pid) unless pid.nil? } | ||
rescue => error | ||
_log.error("Failed to sync_workers for class: #{klass.name}: #{error}") | ||
_log.log_backtrace(error) | ||
next | ||
end | ||
result | ||
end | ||
|
||
def sync_from_system | ||
|
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.
Looks like this line was lost in the refactoring. It was probably added for better diagnostics.
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.
Well removing this was actually the point of this change. We have control over what makes it into
miq_worker_types
so this shouldn't happen. I believe this was from before we had themiq_worker_types
table back when it wasself.class.monitor_class_names
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.
thanks for the explanation
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.
No, this was added specifically because of that weird issue with Ruby where you can ask for a particular constant and get back the wrong one if someone happened to defined one in your module ancestry. See the commit message in afe1f02
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.
Right, but how would one of those "incorrect" class names make it in to
MiqWorkerType
?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.
That being said, afe1f02 was added 2019-10-25, and the refactor into the database table was added in 2947aac on 2019-11-19
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.
Yeah I was thinking if we prevent bad class names from hitting MiqWorkerType in the first place then we don't need to check this at runtime, and everyone else who does constantize on a worker_class_name doesn't have to duplicate this check.
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.
@agrare Oh I'm not disagreeing with you ...just clarifying what the purpose of this line actually was and showing that yes, it was from before the refactor to a table
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.
Yeah, I agree. You're both right. 👍
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.
✂️ 🔥 ✂️ 🔥 ✂️ 🔥
🍰 🍪 👏 🙇 😍 🎉