-
Notifications
You must be signed in to change notification settings - Fork 46
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
Lookup global max_job_runtime
at runtime
#436
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 |
---|---|---|
|
@@ -40,7 +40,7 @@ def inspected_cursor | |
end | ||
end | ||
|
||
included do |_base| | ||
included do |base| | ||
define_callbacks :start | ||
define_callbacks :shutdown | ||
define_callbacks :complete | ||
|
@@ -49,10 +49,16 @@ def inspected_cursor | |
:job_iteration_max_job_runtime, | ||
instance_writer: false, | ||
instance_predicate: false, | ||
default: JobIteration.max_job_runtime, | ||
) | ||
|
||
singleton_class.prepend(PrependedClassMethods) | ||
class << base | ||
prepend(PrependedClassMethods) | ||
|
||
def job_iteration_max_job_runtime | ||
# Lookup default every time, instead of closing around its value when the class is defined. | ||
JobIteration.max_job_runtime | ||
end | ||
Comment on lines
+57
to
+60
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. If I'm reading this code a month from now, I'm not sure it would be clear to me why we're doing this. What is the advantage of this method vs doing 'job_iteration_max_job_runtime || JobIteration.max_job_runtime You could even do 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. +1, I feel like this simplifies the logic, versus having to worry about whether the job-level config is shadowing the global one properly. I don't see that we explicitly mentioned anywhere that |
||
end | ||
end | ||
|
||
module PrependedClassMethods | ||
|
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 think I'm missing something about this. Wouldn't it always return the default, instead of the override?
Why define this method here, rather than with the other methods added by this class, such as
job_should_exit?
?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.
What's doing on here is that we're using
class_attribute
, and the way it implements "inheritable attributes" is that when you invoke the setter method, it redefines the method on the receiver.So stepping through it, this is more or less what happens:
The
include
causes theincluded
block to run which first invokeswhich basically does
Because there's no way to pass in a dynamic default (we want it to delegate to
JobIteration.max_job_runtime
, not use the value at the time the method was defined; that's the bug), the only way to do that is to define the method ourselves, which is what this new part ofincluded
doesFrom there, if a consumer invokes the setter method,
it will redefine the method, "shadowing" the parent one
The semantics of
class_attribute
match what we want, it just doesn't allow for a dynamic default, hence why we have to do this.We can't just put the method in
ClassMethods
, because the method defined byclass_attributes
would shadow it, but it does occur to me we could put it inPrependedClassMethods
, which should shadow theclass_attributes
implementation, while still allowing consumers to override it.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 think part of my confusion comes from
class_attribute
adding both class and instance accessor methods. This implementation only overrides one of them, but not the other, right?