From 98e1848a83ce6fc3660722813d0b3217689e287b Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Tue, 12 Nov 2024 12:17:36 +0100 Subject: [PATCH] add origin to job status metadata --- cads_processing_api_service/models.py | 1 + cads_processing_api_service/utils.py | 18 ++++++++---------- tests/test_30_utils.py | 2 ++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cads_processing_api_service/models.py b/cads_processing_api_service/models.py index 3836b5f..e3476bc 100644 --- a/cads_processing_api_service/models.py +++ b/cads_processing_api_service/models.py @@ -43,6 +43,7 @@ class StatusInfoMetadata(pydantic.BaseModel): datasetMetadata: dict[str, Any] | None = None qos: dict[str, Any] | None = None log: list[tuple[str, str]] | None = None + origin: str | None = None class StatusInfo(ogc_api_processes_fastapi.models.StatusInfo): diff --git a/cads_processing_api_service/utils.py b/cads_processing_api_service/utils.py index 4e780f7..f697712 100644 --- a/cads_processing_api_service/utils.py +++ b/cads_processing_api_service/utils.py @@ -641,14 +641,12 @@ def make_status_info( finished=job["finished_at"], updated=job["updated_at"], ) - if any( - field is not None for field in [request, results, dataset_metadata, qos, log] - ): - status_info.metadata = models.StatusInfoMetadata( - request=request, - results=results, - datasetMetadata=dataset_metadata, - qos=qos, - log=log, - ) + status_info.metadata = models.StatusInfoMetadata( + origin=job.get("origin", None), + request=request, + results=results, + datasetMetadata=dataset_metadata, + qos=qos, + log=log, + ) return status_info diff --git a/tests/test_30_utils.py b/tests/test_30_utils.py index 4153944..b783dcc 100644 --- a/tests/test_30_utils.py +++ b/tests/test_30_utils.py @@ -322,6 +322,7 @@ def test_make_status_info() -> None: "finished_at": "2023-01-01T16:20:12.175021", "updated_at": "2023-01-01T16:20:12.175021", "request_body": {"request": {"product_type": ["reanalysis"]}}, + "origin": "api", } status_info = utils.make_status_info(job) exp_status_info = models.StatusInfo( @@ -333,5 +334,6 @@ def test_make_status_info() -> None: started=job["started_at"], finished=job["finished_at"], updated=job["updated_at"], + metadata={"origin": "api"}, ) assert status_info == exp_status_info