Skip to content
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

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

cmoussa1
Copy link
Member

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 in get_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 a ResourceSet object fails while parsing job records.

@cmoussa1 cmoussa1 added the improvement Upgrades to an already existing feature label Jun 27, 2024
@cmoussa1 cmoussa1 requested a review from jameshcorbett June 27, 2024 20:59
Copy link
Member

@jameshcorbett jameshcorbett left a 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

cmoussa1 added 2 commits June 27, 2024 19:38
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.
@cmoussa1 cmoussa1 force-pushed the view.jobs.cleanup branch 2 times, most recently from 37749de to 208570d Compare June 28, 2024 15:32
Copy link
Member

@jameshcorbett jameshcorbett left a 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
Copy link
Member

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?

Copy link
Member Author

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!

@cmoussa1 cmoussa1 force-pushed the view.jobs.cleanup branch from 208570d to e1c7087 Compare June 28, 2024 19:07
@cmoussa1
Copy link
Member Author

Thanks for reviewing this @jameshcorbett and for putting up with this old code 😆 gonna set MWP here

@cmoussa1
Copy link
Member Author

cmoussa1 commented Jul 1, 2024

@Mergifyio refresh

Copy link
Contributor

mergify bot commented Jul 1, 2024

refresh

✅ Pull request refreshed

@cmoussa1
Copy link
Member Author

cmoussa1 commented Jul 1, 2024

@Mergifyio requeue

Copy link
Contributor

mergify bot commented Jul 1, 2024

requeue

☑️ This pull request is already queued

@cmoussa1
Copy link
Member Author

cmoussa1 commented Jul 1, 2024

@Mergifyio dequeue

Copy link
Contributor

mergify bot commented Jul 1, 2024

dequeue

✅ The pull request has been removed from the queue default

@cmoussa1
Copy link
Member Author

cmoussa1 commented Jul 1, 2024

@Mergifyio requeue

Copy link
Contributor

mergify bot commented Jul 1, 2024

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().
@cmoussa1 cmoussa1 force-pushed the view.jobs.cleanup branch from e1c7087 to caee39f Compare July 1, 2024 21:13
@mergify mergify bot merged commit 6672f86 into flux-framework:master Jul 1, 2024
11 checks passed
@cmoussa1
Copy link
Member Author

cmoussa1 commented Jul 1, 2024

Looks like re-pushing helped get this merged. Great suggestion @grondo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Upgrades to an already existing feature merge-when-passing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants