Skip to content

Commit a673fdb

Browse files
authored
Merge pull request #387 from ynput/384-webactions-add-option-to-abort-action-with-reason
Webactions: Add option to abort action with reason
2 parents 265d7aa + 62969dc commit a673fdb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

api/actions/actions.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,40 @@ async def take_action(
246246
)
247247

248248
return result
249+
250+
251+
class AbortRequestModel(OPModel):
252+
message: str = Field("Action aborted", title="Message")
253+
254+
255+
@router.post("/abort/{token}")
256+
async def abort_action(
257+
request: AbortRequestModel,
258+
token: str = Path(
259+
...,
260+
title="Action Token",
261+
pattern=r"[a-f0-9]{64}",
262+
),
263+
) -> None:
264+
"""called by launcher
265+
266+
This is called by the launcher to abort an action.
267+
"""
268+
269+
res = await Postgres.fetch(
270+
"""
271+
UPDATE events SET status = 'aborted', description = $2
272+
WHERE
273+
hash = $1
274+
AND topic = 'action.launcher'
275+
AND status IN ('pending', 'in_progress')
276+
RETURNING *
277+
""",
278+
token,
279+
request.message,
280+
)
281+
282+
if not res:
283+
raise NotFoundException("Invalid token")
284+
285+
return None

0 commit comments

Comments
 (0)