From 0a0f570bde9512b47d741f1600772b444479a91c Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 28 Aug 2024 16:42:16 +0200 Subject: [PATCH 1/6] do not show dismissed and deleted request in get_jobs --- cads_processing_api_service/clients.py | 9 ++++++++- cads_processing_api_service/utils.py | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cads_processing_api_service/clients.py b/cads_processing_api_service/clients.py index 9e32653..6064fbb 100644 --- a/cads_processing_api_service/clients.py +++ b/cads_processing_api_service/clients.py @@ -281,7 +281,14 @@ def get_jobs( processID: list[str] | None = fastapi.Query(None), status: ( list[ogc_api_processes_fastapi.models.StatusCode] | None - ) = fastapi.Query(None), + ) = fastapi.Query( + [ + ogc_api_processes_fastapi.models.StatusCode.accepted, + ogc_api_processes_fastapi.models.StatusCode.running, + ogc_api_processes_fastapi.models.StatusCode.successful, + ogc_api_processes_fastapi.models.StatusCode.failed, + ] + ), limit: int | None = fastapi.Query(10, ge=1, le=10000), sortby: utils.JobSortCriterion | None = fastapi.Query( utils.JobSortCriterion.created_at_desc diff --git a/cads_processing_api_service/utils.py b/cads_processing_api_service/utils.py index 4ee6b72..18b90a0 100644 --- a/cads_processing_api_service/utils.py +++ b/cads_processing_api_service/utils.py @@ -232,7 +232,6 @@ def apply_job_filters( statement = statement.where( getattr(resource, filter_key).in_(filter_values) ) - statement = statement.where(resource.status != "dismissed") return statement From ddafc097e20eec9e8ed2aaf0beccee83a9424bc1 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 28 Aug 2024 16:44:47 +0200 Subject: [PATCH 2/6] explicitly exclude dismissed jobs from list --- cads_processing_api_service/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cads_processing_api_service/utils.py b/cads_processing_api_service/utils.py index 18b90a0..4ee6b72 100644 --- a/cads_processing_api_service/utils.py +++ b/cads_processing_api_service/utils.py @@ -232,6 +232,7 @@ def apply_job_filters( statement = statement.where( getattr(resource, filter_key).in_(filter_values) ) + statement = statement.where(resource.status != "dismissed") return statement From 2b75bca29193a83115091e6eb023967750ced40b Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 28 Aug 2024 16:48:44 +0200 Subject: [PATCH 3/6] introduce ad-hoc list of admitted status codes --- cads_processing_api_service/clients.py | 4 +--- cads_processing_api_service/models.py | 8 ++++++++ cads_processing_api_service/utils.py | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cads_processing_api_service/clients.py b/cads_processing_api_service/clients.py index 6064fbb..7a9bf37 100644 --- a/cads_processing_api_service/clients.py +++ b/cads_processing_api_service/clients.py @@ -279,9 +279,7 @@ def post_process_execution( def get_jobs( self, processID: list[str] | None = fastapi.Query(None), - status: ( - list[ogc_api_processes_fastapi.models.StatusCode] | None - ) = fastapi.Query( + status: list[models.StatusCode] | None = fastapi.Query( [ ogc_api_processes_fastapi.models.StatusCode.accepted, ogc_api_processes_fastapi.models.StatusCode.running, diff --git a/cads_processing_api_service/models.py b/cads_processing_api_service/models.py index 34cff7f..264e671 100644 --- a/cads_processing_api_service/models.py +++ b/cads_processing_api_service/models.py @@ -15,12 +15,20 @@ # limitations under the License import datetime +import enum from typing import Any import ogc_api_processes_fastapi.models import pydantic +class StatusCode(str, enum.Enum): + accepted: str = "accepted" + running: str = "running" + successful: str = "successful" + failed: str = "failed" + + class StatusInfoMetadata(pydantic.BaseModel): request: dict[str, Any] | None = None results: dict[str, Any] | None = None diff --git a/cads_processing_api_service/utils.py b/cads_processing_api_service/utils.py index 4ee6b72..18b90a0 100644 --- a/cads_processing_api_service/utils.py +++ b/cads_processing_api_service/utils.py @@ -232,7 +232,6 @@ def apply_job_filters( statement = statement.where( getattr(resource, filter_key).in_(filter_values) ) - statement = statement.where(resource.status != "dismissed") return statement From 9a80b76e44cdc1861637370be2cf7f19535e6eb9 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 28 Aug 2024 16:54:41 +0200 Subject: [PATCH 4/6] update unit tests --- tests/test_30_utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_30_utils.py b/tests/test_30_utils.py index 8da0b5a..75a6080 100644 --- a/tests/test_30_utils.py +++ b/tests/test_30_utils.py @@ -96,7 +96,6 @@ def test_apply_job_filters() -> None: exp_params = { "process_id_1": ["process"], "status_1": ["successful", "failed"], - "status_2": "dismissed", } exp_substatement = ( "WHERE system_requests.process_id IN (__[POSTCOMPILE_process_id_1]) " @@ -116,8 +115,8 @@ def test_apply_bookmark() -> None: statement, job_table, cursor, back, sort_key, sort_dir ) compiled_statement = statement.compile() - exp_params = {"created_at_2": "2022-10-24 13:32:03.178397"} - exp_substatement = "WHERE system_requests.created_at > :created_at_2" + exp_params = {"created_at_1": "2022-10-24 13:32:03.178397"} + exp_substatement = "WHERE system_requests.created_at > :created_at_1" assert compiled_statement.params == exp_params assert exp_substatement in compiled_statement.string From 4e5baf984a66a0b09dc19846f24a840b903c00b4 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 28 Aug 2024 17:00:31 +0200 Subject: [PATCH 5/6] update unit-tests --- tests/test_30_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_30_utils.py b/tests/test_30_utils.py index 75a6080..12ed38e 100644 --- a/tests/test_30_utils.py +++ b/tests/test_30_utils.py @@ -115,8 +115,8 @@ def test_apply_bookmark() -> None: statement, job_table, cursor, back, sort_key, sort_dir ) compiled_statement = statement.compile() - exp_params = {"created_at_1": "2022-10-24 13:32:03.178397"} - exp_substatement = "WHERE system_requests.created_at > :created_at_1" + exp_params = {"created_at_2": "2022-10-24 13:32:03.178397"} + exp_substatement = "WHERE system_requests.created_at > :created_at_2" assert compiled_statement.params == exp_params assert exp_substatement in compiled_statement.string From 4d198bbae9c34e65acab2534509d3135104ec790 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 28 Aug 2024 17:03:25 +0200 Subject: [PATCH 6/6] type-check --- cads_processing_api_service/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cads_processing_api_service/serializers.py b/cads_processing_api_service/serializers.py index ea85357..f4e2a8e 100644 --- a/cads_processing_api_service/serializers.py +++ b/cads_processing_api_service/serializers.py @@ -70,7 +70,7 @@ def serialize_process_description( cds_form = db_model.resource_data.form_data # type: ignore process_inputs = {} if cds_form: - process_inputs = translators.translate_cds_form(cds_form) # type: ignore + process_inputs = translators.translate_cds_form(cds_form) retval = ogc_api_processes_fastapi.models.ProcessDescription( **process_summary.model_dump(), inputs=process_inputs,