From 62969dcbe6b7fc5ad05a541140a62a38456f7b10 Mon Sep 17 00:00:00 2001 From: Martastain Date: Fri, 11 Oct 2024 12:29:06 +0200 Subject: [PATCH] feat: abort action endpoint --- api/actions/actions.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/api/actions/actions.py b/api/actions/actions.py index 194e5bb0..aaf7b969 100644 --- a/api/actions/actions.py +++ b/api/actions/actions.py @@ -246,3 +246,40 @@ async def take_action( ) return result + + +class AbortRequestModel(OPModel): + message: str = Field("Action aborted", title="Message") + + +@router.post("/abort/{token}") +async def abort_action( + request: AbortRequestModel, + token: str = Path( + ..., + title="Action Token", + pattern=r"[a-f0-9]{64}", + ), +) -> None: + """called by launcher + + This is called by the launcher to abort an action. + """ + + res = await Postgres.fetch( + """ + UPDATE events SET status = 'aborted', description = $2 + WHERE + hash = $1 + AND topic = 'action.launcher' + AND status IN ('pending', 'in_progress') + RETURNING * + """, + token, + request.message, + ) + + if not res: + raise NotFoundException("Invalid token") + + return None