-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64ce150
commit b16e81e
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
; |
20 changes: 20 additions & 0 deletions
20
spatialprofilingtoolbox/db/data_model/load_query_breakdown.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |