ref #8: [feat] add http endpoint

This commit is contained in:
Azamat 2026-04-02 13:41:41 +03:00
parent bae540427a
commit d2506e0c63
7 changed files with 87 additions and 20 deletions

View file

@ -1,4 +1,3 @@
from collections.abc import Callable
from datetime import datetime
from pathlib import Path
@ -11,25 +10,22 @@ from domain.error import SandboxError, SandboxStartError
from domain.sandbox import SandboxSession, SandboxStatus
from usecase.interface import SandboxRuntime
type NowFactory = Callable[[datetime], datetime]
class DockerSandboxRuntime(SandboxRuntime):
def __init__(
self,
config: SandboxConfig,
client: DockerClient,
now: NowFactory | None = None,
) -> None:
self._config = config
self._client = client
self._now = _current_time if now is None else now
def create(
self,
*,
session_id: str,
chat_id: str,
created_at: datetime,
expires_at: datetime,
) -> SandboxSession:
try:
@ -59,7 +55,7 @@ class DockerSandboxRuntime(SandboxRuntime):
chat_id=chat_id,
container_id=container_id,
status=SandboxStatus.RUNNING,
created_at=self._now(expires_at),
created_at=created_at,
expires_at=expires_at,
)
@ -128,7 +124,3 @@ class DockerSandboxRuntime(SandboxRuntime):
def _host_path(self, path_value: str) -> Path:
return Path(path_value).expanduser().resolve(strict=False)
def _current_time(expires_at: datetime) -> datetime:
return datetime.now(tz=expires_at.tzinfo)