diff --git a/.github/workflows/pylinting.yml b/.github/workflows/pylinting.yml deleted file mode 100644 index 3b2766e4a..000000000 --- a/.github/workflows/pylinting.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: pylinting -run-name: Python linting merged or pull-requested code. -on: - push: - branches: - - 'main' - pull_request: - types: - - opened - - edited - - reopened - - synchronize - -jobs: - do_linting: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Create pip requirements. - run: | - bash build/build_scripts/create_requirements.sh > requirements.txt && - bash build/build_scripts/create_requirements.sh all >> requirements.txt && - echo "pylint" >> requirements.txt - - name: Set up Python 3.9 . - uses: actions/setup-python@v4 - with: - python-version: 3.9 - cache: 'pip' - - name: Install Python dependencies. - run: | - pip install -r requirements.txt - - name: Linting the Python source code. - run: | - pylint --output-format=colorized --rc-file .pylintrc spatialprofilingtoolbox/ | tee linter_output.txt - - name: Upload linter results. - uses: actions/upload-artifact@v3 - with: - name: pylint-results - path: linter_output.txt - if: ${{ always() }} diff --git a/pyproject.toml.unversioned b/pyproject.toml.unversioned index af082812f..82658417e 100644 --- a/pyproject.toml.unversioned +++ b/pyproject.toml.unversioned @@ -191,6 +191,7 @@ packages = [ "delete_feature.py", "upload_sync_small.py", "collection.py", + "load_query.py", ] "spatialprofilingtoolbox.db.data_model" = [ "metaschema.sql", @@ -198,6 +199,8 @@ packages = [ "create_roles.sql", "create_views.sql", "drop_views.sql", + "load_query.sql", + "load_query_breakdown.sql", "fields.tsv", "grant_on_tables.sql", "performance_tweaks.sql", diff --git a/spatialprofilingtoolbox/db/data_model/load_query.sql b/spatialprofilingtoolbox/db/data_model/load_query.sql new file mode 100644 index 000000000..d7dd537b9 --- /dev/null +++ b/spatialprofilingtoolbox/db/data_model/load_query.sql @@ -0,0 +1,21 @@ +SELECT +SUM( + ( + xpath( + '/row/c/text()', + query_to_xml( + format( + 'select count(*) as c from %I.%I', + schema_name, + 'quantitative_feature_value_queue' + ), + FALSE, + TRUE, + '' + ) + ) + )[1]::text::int +) as total_jobs_in_queue +FROM + default_study_lookup.study_lookup +; diff --git a/spatialprofilingtoolbox/db/data_model/load_query_breakdown.sql b/spatialprofilingtoolbox/db/data_model/load_query_breakdown.sql new file mode 100644 index 000000000..d495b3e22 --- /dev/null +++ b/spatialprofilingtoolbox/db/data_model/load_query_breakdown.sql @@ -0,0 +1,20 @@ +SELECT + schema_name, + ( + xpath( + '/row/c/text()', + query_to_xml( + format( + 'select count(*) as c from %I.%I', + schema_name, + 'quantitative_feature_value_queue' + ), + FALSE, + TRUE, + '' + ) + ) + )[1]::text::int AS number_jobs_in_queue +FROM + default_study_lookup.study_lookup +; diff --git a/spatialprofilingtoolbox/db/scripts/load_query.py b/spatialprofilingtoolbox/db/scripts/load_query.py new file mode 100644 index 000000000..e067e15b2 --- /dev/null +++ b/spatialprofilingtoolbox/db/scripts/load_query.py @@ -0,0 +1,53 @@ +"""Utility to print the SQL query that returns the number of computation jobs in the queue.""" + +import argparse +from importlib.resources import as_file +from importlib.resources import files + + +def _get_data_model_file(filename: str) -> str: + source_package = 'spatialprofilingtoolbox.db.data_model' + with as_file(files(source_package).joinpath(filename)) as path: + with open(path, encoding='utf-8') as file: + script = file.read() + return script + +def get_load_query() -> str: + return _get_data_model_file('load_query.sql') + + +def get_load_query_breakdown() -> str: + return _get_data_model_file('load_query_breakdown.sql') + + +def parse_args(): + parser = argparse.ArgumentParser( + prog='spt db load-query', + description='Get a SQL query which returns the size of the computation job queue, suitable as a measure of load.', + ) + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument( + '--all', + action='store_true', + default=False, + help='If selected, the SQL query will be the one which sums all job queue sizes for a single total.', + ) + group.add_argument( + '--breakdown-by-dataset', + action='store_true', + default=False, + help='If selected, the SQL query will return the job queue sizes broken down by dataset.', + ) + return parser.parse_args() + + +def main(): + args = parse_args() + if args.all: + print(get_load_query()) + if args.breakdown_by_dataset: + print(get_load_query_breakdown()) + + +if __name__=='__main__': + main()