|
|
@@ -1,10 +1,11 @@
|
|
|
from __future__ import annotations
|
|
|
|
|
|
from datetime import UTC, datetime
|
|
|
-from typing import Any
|
|
|
+from typing import Any, cast
|
|
|
from uuid import uuid4
|
|
|
|
|
|
from sqlalchemy import insert, select, update
|
|
|
+from sqlalchemy.engine import CursorResult
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
|
|
|
|
|
from script_build_host.domain.errors import BuildNotFound, ProtocolViolation
|
|
|
@@ -39,21 +40,24 @@ class SqlAlchemyLegacyBuildStateRepository:
|
|
|
root_trace_id: str | None = None,
|
|
|
) -> int:
|
|
|
async with self._sessions() as session, session.begin():
|
|
|
- result = await session.execute(
|
|
|
- insert(self._runtime_record).values(
|
|
|
- execution_id=execution_id,
|
|
|
- topic_build_id=topic_build_id,
|
|
|
- topic_id=topic_id,
|
|
|
- agent_type=agent_type,
|
|
|
- agent_config=agent_config,
|
|
|
- data_source_url=data_source_url,
|
|
|
- strategies_config=strategies_config,
|
|
|
- reson_trace_id=root_trace_id or str(uuid4()),
|
|
|
- status=BuildStatus.RUNNING.value,
|
|
|
- is_deleted=False,
|
|
|
- is_favorited=False,
|
|
|
- start_time=datetime.now(UTC),
|
|
|
- )
|
|
|
+ result = cast(
|
|
|
+ CursorResult[Any],
|
|
|
+ await session.execute(
|
|
|
+ insert(self._runtime_record).values(
|
|
|
+ execution_id=execution_id,
|
|
|
+ topic_build_id=topic_build_id,
|
|
|
+ topic_id=topic_id,
|
|
|
+ agent_type=agent_type,
|
|
|
+ agent_config=agent_config,
|
|
|
+ data_source_url=data_source_url,
|
|
|
+ strategies_config=strategies_config,
|
|
|
+ reson_trace_id=root_trace_id or str(uuid4()),
|
|
|
+ status=BuildStatus.RUNNING.value,
|
|
|
+ is_deleted=False,
|
|
|
+ is_favorited=False,
|
|
|
+ start_time=datetime.now(UTC),
|
|
|
+ )
|
|
|
+ ),
|
|
|
)
|
|
|
primary_key = result.inserted_primary_key
|
|
|
if primary_key is None or primary_key[0] is None:
|
|
|
@@ -77,13 +81,16 @@ class SqlAlchemyLegacyBuildStateRepository:
|
|
|
}:
|
|
|
values["end_time"] = datetime.now(UTC)
|
|
|
async with self._sessions() as session, session.begin():
|
|
|
- result = await session.execute(
|
|
|
- update(self._runtime_record)
|
|
|
- .where(
|
|
|
- self._runtime_record.c.id == script_build_id,
|
|
|
- self._runtime_record.c.is_deleted.is_(False),
|
|
|
- )
|
|
|
- .values(**values)
|
|
|
+ result = cast(
|
|
|
+ CursorResult[Any],
|
|
|
+ await session.execute(
|
|
|
+ update(self._runtime_record)
|
|
|
+ .where(
|
|
|
+ self._runtime_record.c.id == script_build_id,
|
|
|
+ self._runtime_record.c.is_deleted.is_(False),
|
|
|
+ )
|
|
|
+ .values(**values)
|
|
|
+ ),
|
|
|
)
|
|
|
if result.rowcount != 1:
|
|
|
raise BuildNotFound()
|
|
|
@@ -102,13 +109,16 @@ class SqlAlchemyLegacyBuildStateRepository:
|
|
|
|
|
|
async def project_direction(self, script_build_id: int, legacy_markdown: str) -> None:
|
|
|
async with self._sessions() as session, session.begin():
|
|
|
- result = await session.execute(
|
|
|
- update(self._runtime_record)
|
|
|
- .where(
|
|
|
- self._runtime_record.c.id == script_build_id,
|
|
|
- self._runtime_record.c.is_deleted.is_(False),
|
|
|
- )
|
|
|
- .values(script_direction=legacy_markdown)
|
|
|
+ result = cast(
|
|
|
+ CursorResult[Any],
|
|
|
+ await session.execute(
|
|
|
+ update(self._runtime_record)
|
|
|
+ .where(
|
|
|
+ self._runtime_record.c.id == script_build_id,
|
|
|
+ self._runtime_record.c.is_deleted.is_(False),
|
|
|
+ )
|
|
|
+ .values(script_direction=legacy_markdown)
|
|
|
+ ),
|
|
|
)
|
|
|
if result.rowcount != 1:
|
|
|
raise BuildNotFound()
|
|
|
@@ -139,13 +149,16 @@ class SqlAlchemyLegacyBuildStateRepository:
|
|
|
"end_time": datetime.now(UTC),
|
|
|
}
|
|
|
async with self._sessions() as session, session.begin():
|
|
|
- result = await session.execute(
|
|
|
- update(self._runtime_record)
|
|
|
- .where(
|
|
|
- self._runtime_record.c.id == script_build_id,
|
|
|
- self._runtime_record.c.is_deleted.is_(False),
|
|
|
- )
|
|
|
- .values(**values)
|
|
|
+ result = cast(
|
|
|
+ CursorResult[Any],
|
|
|
+ await session.execute(
|
|
|
+ update(self._runtime_record)
|
|
|
+ .where(
|
|
|
+ self._runtime_record.c.id == script_build_id,
|
|
|
+ self._runtime_record.c.is_deleted.is_(False),
|
|
|
+ )
|
|
|
+ .values(**values)
|
|
|
+ ),
|
|
|
)
|
|
|
if result.rowcount != 1:
|
|
|
raise BuildNotFound()
|