Skip to content

Commit

Permalink
Merge branch 'main' into COPDS-2173-costing-min-cost
Browse files Browse the repository at this point in the history
  • Loading branch information
mcucchi9 committed Nov 19, 2024
2 parents 50e69ff + 28b1109 commit 1aec305
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
7 changes: 7 additions & 0 deletions cads_processing_api_service/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ def post_process_execution(
)
structlog.contextvars.bind_contextvars(user_uid=auth_info.user_uid)
request_body = execution_content.model_dump()
portals = (
[p.strip() for p in auth_info.portal_header.split(",")]
if auth_info.portal_header
else None
)
catalogue_sessionmaker = db_utils.get_catalogue_sessionmaker(
db_utils.ConnectionMode.read
)
Expand All @@ -228,6 +233,7 @@ def post_process_execution(
table=self.process_table,
session=catalogue_session,
load_messages=True,
portals=tuple(portals),
)
auth.verify_if_disabled(dataset.disabled_reason, auth_info.user_role)
adaptor_properties = adaptors.get_adaptor_properties(dataset)
Expand Down Expand Up @@ -295,6 +301,7 @@ def post_process_execution(
content=message.content,
)
for message in dataset.messages
if message.live
]
url = str(request.url)
if url.rstrip("/").endswith("execute"):
Expand Down
1 change: 1 addition & 0 deletions cads_processing_api_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 15 additions & 11 deletions cads_processing_api_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ class JobSortCriterion(str, enum.Enum):
key=lambda resource_id,
table,
session,
load_messages=False: cachetools.keys.hashkey(resource_id, table, load_messages),
load_messages=False,
portals=None: cachetools.keys.hashkey(resource_id, table, load_messages, portals),
)
def lookup_resource_by_id(
resource_id: str,
table: type[cads_catalogue.database.Resource],
session: sqlalchemy.orm.Session,
load_messages: bool = False,
portals: tuple[str] | None = None,
) -> cads_catalogue.database.Resource:
"""Look for the resource identified by `id` into the Catalogue database.
Expand All @@ -82,6 +84,8 @@ def lookup_resource_by_id(
Catalogue database session.
load_messages : bool, optional
If True, load resource messages, by default False.
portals: tuple[str] | None, optional
Portals to filter resources by, by default None.
Returns
-------
Expand All @@ -100,6 +104,8 @@ def lookup_resource_by_id(
)
if load_messages:
statement = statement.options(sqlalchemy.orm.joinedload(table.messages))
if portals:
statement = statement.filter(table.portal.in_(portals))
statement = statement.filter(table.resource_uid == resource_id)
try:
row: cads_catalogue.database.Resource = (
Expand Down Expand Up @@ -641,14 +647,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
2 changes: 2 additions & 0 deletions tests/test_30_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,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(
Expand All @@ -329,5 +330,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

0 comments on commit 1aec305

Please sign in to comment.