-
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
Enable per job class max_job_runtime
#240
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 |
---|---|---|
|
@@ -39,6 +39,33 @@ def inspected_cursor | |
define_callbacks :start | ||
define_callbacks :shutdown | ||
define_callbacks :complete | ||
|
||
class_attribute( | ||
:job_iteration_max_job_runtime, | ||
instance_writer: false, | ||
instance_predicate: false, | ||
default: JobIteration.max_job_runtime, | ||
) | ||
|
||
singleton_class.prepend(PrependedClassMethods) | ||
end | ||
|
||
module PrependedClassMethods | ||
def job_iteration_max_job_runtime=(new) | ||
existing = job_iteration_max_job_runtime | ||
|
||
if existing && (!new || new > existing) | ||
sambostock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
existing_label = existing.inspect | ||
new_label = new ? new.inspect : "#{new.inspect} (no limit)" | ||
raise( | ||
ArgumentError, | ||
"job_iteration_max_job_runtime may only decrease; " \ | ||
"#{self} tried to increase it from #{existing_label} to #{new_label}", | ||
) | ||
end | ||
|
||
super | ||
end | ||
end | ||
|
||
module ClassMethods | ||
|
@@ -262,7 +289,7 @@ def output_interrupt_summary | |
end | ||
|
||
def job_should_exit? | ||
if ::JobIteration.max_job_runtime && start_time && (Time.now.utc - start_time) > ::JobIteration.max_job_runtime | ||
if job_iteration_max_job_runtime && start_time && (Time.now.utc - start_time) > job_iteration_max_job_runtime | ||
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. As a user of the library, it would be helpful if there was an easy way to get notified (as in 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. We do instrument that a job has been interrupted, although we do not note the reason why. I think that could be something worth considering, but I would consider it outside the scope of this PR. I've opened #247 to capture the discussion. 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. Sorry to comment on such an old PR, please let me know if you'd rather I convert this to an issue, or move the conversation somewhere else. This change actually creates a subtle behaviour change. Previously, we read the global configuration at job runtime. Now, we read the global configuration when Today, we noticed that maintenance tasks were never pausing because that gem were setting a default job runtime in an I'm not actually sure which option is better. Just wanted to point out the difference in behaviours. In the meantime, I've proposed Shopify/maintenance_tasks#918 to fix maintenance tasks under the assumption that the current behaviour of job-iteration is 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. Oof, nice catch! I'd consider that a bug - changes to the global value should be picked up by the jobs as they run. I'm not entirely sure what the best fix is, especially in a way that enforces the "individual jobs must not increase this value". 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. I can try to have a look on Monday, but I think the fix would be to override the method defined by 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. #436 should fix this. |
||
return true | ||
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 have renamed the class attribute 👍