Skip to content

Commit 77ad0a3

Browse files
authored
Merge pull request #253 from ecmwf-projects/COPDS-2727-status-rejected
Support status "rejected"
2 parents 7c59dbf + 55eef33 commit 77ad0a3

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

cads_processing_api_service/clients.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,13 @@ def get_jobs(
334334
"processes shall be included in the response."
335335
),
336336
),
337-
status: list[models.StatusCode] | None = fastapi.Query(
337+
status: list[models.SearchableStatusCode] | None = fastapi.Query(
338338
[
339-
ogc_api_processes_fastapi.models.StatusCode.accepted,
340-
ogc_api_processes_fastapi.models.StatusCode.running,
341-
ogc_api_processes_fastapi.models.StatusCode.successful,
342-
ogc_api_processes_fastapi.models.StatusCode.failed,
339+
models.StatusCode.accepted,
340+
models.StatusCode.running,
341+
models.StatusCode.successful,
342+
models.StatusCode.failed,
343+
models.StatusCode.rejected,
343344
],
344345
description=(
345346
"Job statuses. Only jobs with the specified statuses shall be included in "
@@ -677,7 +678,7 @@ def delete_job(
677678
self,
678679
job_id: str = fastapi.Path(..., description="Job identifier."),
679680
auth_info: models.AuthInfo = fastapi.Depends(auth.get_auth_info),
680-
) -> ogc_api_processes_fastapi.models.StatusInfo:
681+
) -> models.StatusInfo:
681682
"""Implement OGC API - Processes `DELETE /jobs/{job_id}` endpoint.
682683
683684
Dismiss the job identifed by `job_id`.
@@ -691,7 +692,7 @@ def delete_job(
691692
692693
Returns
693694
-------
694-
ogc_api_processes_fastapi.models.StatusInfo
695+
models.StatusInfo
695696
Job status information
696697
"""
697698
structlog.contextvars.bind_contextvars(user_uid=auth_info.user_uid)

cads_processing_api_service/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ class StatusCode(str, enum.Enum):
3636
running = "running"
3737
successful = "successful"
3838
failed = "failed"
39+
rejected = "rejected"
40+
dismissed = "dismissed"
41+
42+
43+
class SearchableStatusCode(str, enum.Enum):
44+
accepted = "accepted"
45+
running = "running"
46+
successful = "successful"
47+
failed = "failed"
48+
rejected = "rejected"
3949

4050

4151
class StatusInfoMetadata(pydantic.BaseModel):
@@ -48,6 +58,7 @@ class StatusInfoMetadata(pydantic.BaseModel):
4858

4959

5060
class StatusInfo(ogc_api_processes_fastapi.models.StatusInfo):
61+
status: StatusCode # type: ignore
5162
metadata: StatusInfoMetadata | None = None
5263

5364

cads_processing_api_service/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ def apply_limit(
395395

396396
def make_cursor(
397397
entries: (
398-
list[ogc_api_processes_fastapi.models.StatusInfo]
399-
| list[ogc_api_processes_fastapi.models.ProcessSummary]
398+
list[models.StatusInfo] | list[ogc_api_processes_fastapi.models.ProcessSummary]
400399
),
401400
sort_key: str,
402401
page: str,
@@ -413,8 +412,7 @@ def make_cursor(
413412

414413
def make_pagination_query_params(
415414
entries: (
416-
list[ogc_api_processes_fastapi.models.StatusInfo]
417-
| list[ogc_api_processes_fastapi.models.ProcessSummary]
415+
list[models.StatusInfo] | list[ogc_api_processes_fastapi.models.ProcessSummary]
418416
),
419417
sort_key: str,
420418
) -> ogc_api_processes_fastapi.models.PaginationQueryParameters:
@@ -521,13 +519,18 @@ def get_results_from_job(
521519
asset_value["file:local_path"], config.DownloadNodesSettings().download_node
522520
)
523521
results = {"asset": {"value": asset_value}}
524-
elif job_status == "failed":
522+
elif job_status in ("failed", "rejected"):
525523
error_messages = get_job_events(
526524
job=job, session=session, event_type="user_visible_error"
527525
)
528526
traceback = "\n".join([message[1] for message in error_messages])
527+
match job_status:
528+
case "failed":
529+
exc_title = "The job has failed"
530+
case "rejected":
531+
exc_title = "The job has been rejected"
529532
raise ogc_api_processes_fastapi.exceptions.JobResultsFailed(
530-
title="The job has failed.",
533+
title=exc_title, # type: ignore
531534
status_code=fastapi.status.HTTP_400_BAD_REQUEST,
532535
traceback=traceback,
533536
)

0 commit comments

Comments
 (0)