generated from coulomb/repo-seed
feat(workflows): TaskExecutorWorkflow stub + wire worker — T19/T20
activities.py — persist_task_instance (new): Idempotent INSERT ... ON CONFLICT (id) DO NOTHING on task_instances. task_id passed in from workflow (derived from workflow_id via uuid5). Registered on task-execution-tq. workflows.py — TaskExecutorWorkflow (T19): Derives stable task_id = uuid5(NAMESPACE_URL, workflow_id). Calls persist_task_instance → status=done, returns immediately. Real execution logic to replace stub in a later workstream. worker.py — T20: Registers persist_task_instance on task-execution-tq Worker. Both queues fully wired: orchestrator-tq and task-execution-tq. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,7 +22,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
|
||||
from activity_core.orm import ActivityRun, TaskInstance
|
||||
|
||||
|
||||
_session_factory: async_sessionmaker[AsyncSession] | None = None
|
||||
@@ -162,3 +162,41 @@ async def log_run(run_payload: dict) -> str:
|
||||
await session.execute(stmt)
|
||||
|
||||
return str(run_id)
|
||||
|
||||
|
||||
@activity.defn
|
||||
async def persist_task_instance(task_payload: dict) -> str:
|
||||
"""Write a TaskInstance row and return its id.
|
||||
|
||||
Idempotent: uses INSERT … ON CONFLICT (id) DO NOTHING.
|
||||
|
||||
Expected keys in task_payload:
|
||||
id (str UUID — deterministic, computed in TaskExecutorWorkflow)
|
||||
run_id (str UUID)
|
||||
type (str)
|
||||
params (dict)
|
||||
status (str, default "done" for stub)
|
||||
|
||||
Returns:
|
||||
task instance id as a str UUID.
|
||||
"""
|
||||
Session = _get_session_factory()
|
||||
task_id = uuid.UUID(task_payload["id"])
|
||||
|
||||
stmt = (
|
||||
pg_insert(TaskInstance)
|
||||
.values(
|
||||
id=task_id,
|
||||
run_id=uuid.UUID(task_payload["run_id"]),
|
||||
type=task_payload["type"],
|
||||
params=task_payload.get("params", {}),
|
||||
status=task_payload.get("status", "done"),
|
||||
)
|
||||
.on_conflict_do_nothing(index_elements=["id"])
|
||||
)
|
||||
|
||||
async with Session() as session:
|
||||
async with session.begin():
|
||||
await session.execute(stmt)
|
||||
|
||||
return str(task_id)
|
||||
|
||||
Reference in New Issue
Block a user