Skip to content

Commit

Permalink
Merge pull request #387 from ynput/384-webactions-add-option-to-abort…
Browse files Browse the repository at this point in the history
…-action-with-reason

Webactions: Add option to abort action with reason
  • Loading branch information
martastain authored Oct 11, 2024
2 parents 265d7aa + 62969dc commit a673fdb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions api/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a673fdb

Please sign in to comment.