Skip to content

Commit

Permalink
core: services: versionchooser: main: Make set operations to wait for…
Browse files Browse the repository at this point in the history
… what is already in progress

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed Apr 13, 2024
1 parent 84092de commit 1f02cd6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/services/versionchooser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import aiodocker
import connexion
from aiohttp import web
from commonwealth.utils.decorators import operation_in_progress_global
from commonwealth.utils.logs import InterceptHandler, init_logger
from fastapi import HTTPException, status
from loguru import logger

from utils.chooser import STATIC_FOLDER, VersionChooser
Expand All @@ -20,6 +22,15 @@
versionChooser = VersionChooser(aiodocker.Docker())


def raise_lock(*raise_args: str, **kwargs: int) -> None:
"""Raise a 423 HTTP Error status
Raises:
HTTPException: An operation is already in progress, please wait.
"""
raise HTTPException(status_code=status.HTTP_423_LOCKED, detail="There is an operation already in progress.")


async def index(_request: web.Request) -> Any:
return versionChooser.index()

Expand All @@ -28,20 +39,23 @@ async def get_version() -> Any:
return versionChooser.get_version()


@operation_in_progress_global(callback=raise_lock)
async def pull_version(request: web.Request) -> Any:
data = await request.json()
repository = data["repository"]
tag = data["tag"]
return await versionChooser.pull_version(request, repository, tag)


@operation_in_progress_global(callback=raise_lock)
async def set_version(request: web.Request) -> Any:
data = await request.json()
tag = data["tag"]
repository = data["repository"]
return await versionChooser.set_version(repository, tag)


@operation_in_progress_global(callback=raise_lock)
async def delete_version(request: web.Request) -> Any:
data = await request.json()
tag = data["tag"]
Expand All @@ -61,17 +75,20 @@ async def get_bootstrap_version() -> Any:
return await versionChooser.get_bootstrap_version()


@operation_in_progress_global(callback=raise_lock)
async def set_bootstrap_version(request: web.Request) -> Any:
data = await request.json()
tag = data["tag"]
return await versionChooser.set_bootstrap_version(tag)


@operation_in_progress_global(callback=raise_lock)
async def load(request: web.Request) -> Any:
data = await request.read()
return await versionChooser.load(data)


@operation_in_progress_global(callback=raise_lock)
async def restart() -> Any:
return await versionChooser.restart()

Expand Down

0 comments on commit 1f02cd6

Please sign in to comment.