-
Notifications
You must be signed in to change notification settings - Fork 10
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
job archive interface: clean up a couple helper functions #460
Conversation
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 am puzzled by some things 😖 but it otherwise looks good
src/bindings/python/fluxacct/accounting/job_archive_interface.py
Outdated
Show resolved
Hide resolved
Problem: There are a few improvements that can be made to enhance readability, efficiency, and maintainability of this function. Simplify the construction of the params dictionary. Use f-strings for string formatting of the SELECT statement and WHERE clauses. Remove the unnecessary check for len(result) == 0 since we can just return an empty list if no records are found.
Problem: The add_job_records() function does not handle the case where a ResourceSet object cannot be created out of the R fetched for each job. Add a try-except block for this, and just skip adding the record in the case where the creation of the ResourceSet object does not work since it will not contribute to an association's job usage or fair-share value.
37749de
to
208570d
Compare
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.
One nit, otherwise things are good! I was just confused 😖
# one of their secondary banks; this will determine how we filter the | ||
# job records we've found | ||
is_default_bank = bank == default_bank | ||
bank = bank if bank != default_bank else default_bank |
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.
Isn't this line not doing anything? Like wouldn't bank
come out unchanged after going through this if/else statement?
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.
🤦 you're absolutely right. Sorry about that. I'll remove this line. Thanks for pointing that out!
208570d
to
e1c7087
Compare
Thanks for reviewing this @jameshcorbett and for putting up with this old code 😆 gonna set MWP here |
@Mergifyio refresh |
✅ Pull request refreshed |
@Mergifyio requeue |
☑️ This pull request is already queued |
@Mergifyio dequeue |
✅ The pull request has been removed from the queue
|
@Mergifyio requeue |
✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically |
Problem: The def_bank_jobs() and sec_bank_jobs() helper functions are very similar and could be condensed into one helper function. Combine the two into one filter_jobs_by_bank() function. Add another parameter to the function definition to handle the case for jobs that do not specify any bank. Use this new helper function in get_job_records().
e1c7087
to
caee39f
Compare
Looks like re-pushing helped get this merged. Great suggestion @grondo! |
Problem
There are a few functions in
job_archive_interface.py
that could use some improvements to their error handling and parameter and string construction. There's also some opportunity for some duplicate code cleanup.This PR just makes some minor cleanup in a couple of functions in
job_archive_interface.py
. Notably, it reduces a couple of unnecessary checks inget_job_records()
and makes use of f-strings for the query construction.Some duplicate code is cleaned up in the helper functions for filtering jobs by default/secondary banks by reducing them into just one
filter_jobs_by_bank()
function.Some more explicit error handling is added to
add_job_records()
to handle the case where the construction of aResourceSet
object fails while parsing job records.