95 lines
2.2 KiB
Python
95 lines
2.2 KiB
Python
from collections.abc import Mapping
|
|
from datetime import datetime
|
|
from types import TracebackType
|
|
from typing import Protocol, TypeAlias
|
|
|
|
from domain.sandbox import SandboxSession
|
|
from domain.user import User
|
|
|
|
AttrValue: TypeAlias = str | int | float | bool
|
|
Attrs: TypeAlias = Mapping[str, AttrValue]
|
|
|
|
|
|
class UserRepository(Protocol):
|
|
def get(self, user_id: str) -> User | None: ...
|
|
|
|
def get_by_email(self, email: str) -> User | None: ...
|
|
|
|
def save(self, user: User) -> None: ...
|
|
|
|
|
|
class SandboxSessionRepository(Protocol):
|
|
def get_active_by_chat_id(self, chat_id: str) -> SandboxSession | None: ...
|
|
|
|
def list_expired(self, now: datetime) -> list[SandboxSession]: ...
|
|
|
|
def save(self, session: SandboxSession) -> None: ...
|
|
|
|
def delete(self, session_id: str) -> None: ...
|
|
|
|
|
|
class SandboxRuntime(Protocol):
|
|
def create(
|
|
self,
|
|
*,
|
|
session_id: str,
|
|
chat_id: str,
|
|
expires_at: datetime,
|
|
) -> SandboxSession: ...
|
|
|
|
def stop(self, container_id: str) -> None: ...
|
|
|
|
|
|
class Clock(Protocol):
|
|
def now(self) -> datetime: ...
|
|
|
|
|
|
class Logger(Protocol):
|
|
def debug(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
def info(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
def warning(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
def error(self, message: str, attrs: Attrs | None = None) -> None: ...
|
|
|
|
|
|
class Metrics(Protocol):
|
|
def increment(
|
|
self,
|
|
name: str,
|
|
value: int = 1,
|
|
attrs: Attrs | None = None,
|
|
) -> None: ...
|
|
|
|
def record(
|
|
self,
|
|
name: str,
|
|
value: float,
|
|
attrs: Attrs | None = None,
|
|
) -> None: ...
|
|
|
|
|
|
class Span(Protocol):
|
|
def set_attribute(self, name: str, value: AttrValue) -> None: ...
|
|
|
|
def record_error(self, error: Exception) -> None: ...
|
|
|
|
|
|
class SpanContext(Protocol):
|
|
def __enter__(self) -> Span: ...
|
|
|
|
def __exit__(
|
|
self,
|
|
exc_type: type[BaseException] | None,
|
|
exc: BaseException | None,
|
|
traceback: TracebackType | None,
|
|
) -> bool | None: ...
|
|
|
|
|
|
class Tracer(Protocol):
|
|
def start_span(
|
|
self,
|
|
name: str,
|
|
attrs: Attrs | None = None,
|
|
) -> SpanContext: ...
|