generated from coulomb/repo-seed
feat(activities): implement log_run — T17
Inserts an ActivityRun row via the shared session factory. Accepts run_payload dict with activity_id, scheduled_for (ISO-8601 or None), context_snapshot, tasks_spawned, version_used. Returns run_id as a str UUID. fired_at is set server-side to now(UTC). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ activities that need DB access.
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
@@ -20,6 +21,7 @@ from temporalio.exceptions import ApplicationError
|
||||
|
||||
from activity_core.db import make_engine
|
||||
from activity_core.orm import ActivityDefinition as ActivityDefinitionRow
|
||||
from activity_core.orm import ActivityRun
|
||||
|
||||
|
||||
_session_factory: async_sessionmaker[AsyncSession] | None = None
|
||||
@@ -116,8 +118,35 @@ async def resolve_context(context_sources: list[dict]) -> dict:
|
||||
|
||||
@activity.defn
|
||||
async def log_run(run_payload: dict) -> str:
|
||||
"""Persist an ActivityRun record and return its run_id.
|
||||
"""Persist an ActivityRun record to Postgres and return its run_id.
|
||||
|
||||
Implemented in T17.
|
||||
Expected keys in run_payload:
|
||||
activity_id (str UUID)
|
||||
scheduled_for (ISO-8601 str or None)
|
||||
context_snapshot (dict)
|
||||
tasks_spawned (int)
|
||||
version_used (int)
|
||||
|
||||
Returns:
|
||||
run_id as a str UUID.
|
||||
"""
|
||||
raise NotImplementedError("T17")
|
||||
Session = _get_session_factory()
|
||||
|
||||
scheduled_for: datetime | None = None
|
||||
if run_payload.get("scheduled_for"):
|
||||
scheduled_for = datetime.fromisoformat(run_payload["scheduled_for"])
|
||||
|
||||
row = ActivityRun(
|
||||
activity_id=uuid.UUID(run_payload["activity_id"]),
|
||||
scheduled_for=scheduled_for,
|
||||
fired_at=datetime.now(tz=timezone.utc),
|
||||
context_snapshot=run_payload["context_snapshot"],
|
||||
tasks_spawned=run_payload["tasks_spawned"],
|
||||
version_used=run_payload["version_used"],
|
||||
)
|
||||
|
||||
async with Session() as session:
|
||||
async with session.begin():
|
||||
session.add(row)
|
||||
|
||||
return str(row.run_id)
|
||||
|
||||
@@ -72,7 +72,7 @@ tasks:
|
||||
state_hub_task_id: b7decbb6-ad2b-4fa5-8efc-05a7eb435d76
|
||||
- id: T17
|
||||
title: Implement log_run activity
|
||||
status: todo
|
||||
status: done
|
||||
state_hub_task_id: e019cb5a-adf0-4a5d-9410-c41810128190
|
||||
- id: T18
|
||||
title: Implement RunActivityWorkflow
|
||||
|
||||
Reference in New Issue
Block a user