Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webactions: Add option to abort action with reason #387

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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