-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api-server] fix typings, update dependencies (#886)
* upate deps Signed-off-by: Teo Koon Peng <[email protected]> * make pylance happy Signed-off-by: Teo Koon Peng <[email protected]> * tests finally passing Signed-off-by: Teo Koon Peng <[email protected]> * make pylint happy Signed-off-by: Teo Koon Peng <[email protected]> * fix imports Signed-off-by: Teo Koon Peng <[email protected]> * fix imports Signed-off-by: Teo Koon Peng <[email protected]> * ignore pyright false positive Signed-off-by: Teo Koon Peng <[email protected]> * fix stub authenticator Signed-off-by: Teo Koon Peng <[email protected]> * fix health not being written to db Signed-off-by: Teo Koon Peng <[email protected]> --------- Signed-off-by: Teo Koon Peng <[email protected]>
- Loading branch information
Teo Koon Peng
authored
Jan 30, 2024
1 parent
5840346
commit 9567672
Showing
62 changed files
with
1,568 additions
and
1,162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from . import tortoise_models as ttm | ||
from .health import BasicHealth, HealthStatus | ||
|
||
|
||
class RobotHealth(BasicHealth): | ||
@classmethod | ||
async def from_tortoise_orm(cls, obj: ttm.RobotHealth) -> "RobotHealth": | ||
return RobotHealth( | ||
id_=obj.id_, | ||
health_status=HealthStatus(obj.health_status), | ||
health_message=obj.health_message, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,15 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Generic, Optional, Type, TypeVar, cast | ||
from enum import Enum | ||
|
||
from tortoise.contrib.pydantic.base import PydanticModel | ||
from tortoise.contrib.pydantic.creator import pydantic_model_creator | ||
from pydantic import BaseModel | ||
|
||
from . import tortoise_models as ttm | ||
|
||
|
||
class HealthStatus: | ||
class HealthStatus(str, Enum): | ||
HEALTHY = "Healthy" | ||
UNHEALTHY = "Unhealthy" | ||
DEAD = "Dead" | ||
|
||
|
||
HealthModelT = TypeVar("HealthModelT", bound=ttm.BasicHealthModel) | ||
|
||
|
||
class BaseBasicHealth(Generic[HealthModelT], ABC, PydanticModel): | ||
class BasicHealth(BaseModel): | ||
id_: str | ||
health_status: str | ||
health_message: Optional[str] | ||
|
||
@staticmethod | ||
@abstractmethod | ||
async def from_tortoise(_tortoise: HealthModelT) -> "BaseBasicHealth": | ||
pass | ||
|
||
@abstractmethod | ||
async def save(self) -> None: | ||
pass | ||
|
||
|
||
def basic_health_model( | ||
TortoiseModel: Type[HealthModelT], | ||
) -> Type[BaseBasicHealth[HealthModelT]]: | ||
""" | ||
Creates a pydantic model from a tortoise basic health model. | ||
""" | ||
|
||
class _BasicHealth(pydantic_model_creator(TortoiseModel)): | ||
id_: str | ||
health_status: str | ||
health_message: Optional[str] | ||
|
||
@classmethod | ||
async def from_tortoise(cls, tortoise: ttm.BasicHealthModel): | ||
return await cls.from_tortoise_orm(tortoise) | ||
|
||
async def save(self): | ||
dic = self.dict() | ||
del dic["id_"] | ||
await TortoiseModel.update_or_create(dic, id_=self.id_) | ||
|
||
_BasicHealth.__name__ = TortoiseModel.__name__ | ||
|
||
return cast(Type[BaseBasicHealth[HealthModelT]], _BasicHealth) | ||
health_status: HealthStatus | ||
health_message: str | None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.