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

python: clean job-archive interface code #463

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

cmoussa1
Copy link
Member

@cmoussa1 cmoussa1 commented Jul 9, 2024

Problem

The code for both viewing job records in the flux-accounting database and calculating/updating job usage values is in the same file, job_archive_interface.py. This causes the file to be very large and hard to read; it would be best to separate these two different features (viewing job records & calculating usage) into two, smaller files, as well as clean up some of the existing code for viewing job records.


This PR moves the code for viewing job records into a new file called jobs_table_subcommands.py. It also makes some slight improvements to the function names and adds some descriptions to a couple of those moved functions to better represent what they are doing.

The code in job_archive_interface.py (renamed to job_usage_calculation.py), the flux-accounting service, and unit tests are adjusted to account for this moved code.

Problem: The code for both viewing job records in the flux-accounting
database and calculating/updating job usage values is in the same file,
job_archive_interface.py. This causes the file to be very large and hard
to read; it would be best to separate these two different features
(viewing job records & calculating usage) into two, smaller files.

Move the code for viewing job records into a new file called
jobs_table_subcommands.py.

Adjust the code in job_archive_interface.py, the flux-accounting
service, and t1006_job_archive.py to account for the newly-moved code.
@cmoussa1 cmoussa1 added the improvement Upgrades to an already existing feature label Jul 9, 2024
@cmoussa1 cmoussa1 requested a review from jameshcorbett July 9, 2024 16:10
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.

Looks good to me. It looks like a lot of the python code in this repo has function descriptions like

# description
def function():
    pass

or

def function():
    # description
    pass

but I think the usual Python style is

def function():
    """description"""

I noticed it in some of the code in this PR and then saw that it was pretty consistent across the repo.

@@ -88,7 +88,9 @@ def write_records_to_file(job_records, output_file):
)


def fetch_job_records(job_records):
# Convert the results of a query to the jobs table to a readable string
# that can either be output to stdout or written to a file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the style police 👮‍♂️ 🚔 you have violated the law

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👐 i swear i'm innocent!

I will change the style of the function descriptions that I've created in this PR. If it's okay, I'll open a separate one to fix the descriptions in the rest of the repo.

cmoussa1 added 3 commits July 9, 2024 12:53
Problem: Some of the functions moved over from job_archive_interface
could use better names, function definitions, and descriptions.

Change the names of a couple of the functions to better reflect what
they do. Add a couple function descriptions where appropriate.

Add a small helper function to filter queried jobs by user before
filtering those jobs by bank.

Adjust the flux-accounting service and t1006_job_archive.py to account
for the name changes to a couple of the functions.
Problem: job_archive_interface.py could use a better filename since the
contents of the file have changed. The code in this file primarily
focuses on calculating and updating job usage values for associations in
the flux-accounting database.

Rename job_archive_interface --> job_usage_calculation. Adjust the
various files that list and import this file to account for the name
change.
Problem: There is a leftover print() statement in one of the unit tests
in t1006_job_archive.py that is not needed.

Remove it.
@cmoussa1 cmoussa1 force-pushed the clean.job-archive-interface branch from ff1c091 to 39f1a8a Compare July 9, 2024 20:02
@cmoussa1
Copy link
Member Author

cmoussa1 commented Jul 9, 2024

Thanks for reviewing @jameshcorbett. I've pushed up a fix to the function descriptions I wrote in this PR. I'll open up an issue to step through the Python code in this repo and update the rest of the function descriptions. Setting MWP here

@mergify mergify bot merged commit f15bbcc into flux-framework:master Jul 9, 2024
11 checks passed
@cmoussa1 cmoussa1 deleted the clean.job-archive-interface branch February 13, 2025 18:21
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