generated from coulomb/repo-seed
feat(worker): scaffold activities, workflows, worker entrypoint — T13
src/activity_core/activities.py:
- load_activity_definition, resolve_context, log_run — @activity.defn
stubs (raise NotImplementedError, bodies in T14–T17)
src/activity_core/workflows.py:
- RunActivityWorkflow (orchestrator-tq) — @workflow.defn stub (T18)
- TaskExecutorWorkflow (task-execution-tq) — @workflow.defn stub (T19)
src/activity_core/worker.py:
- Connects to Temporal via TEMPORAL_HOST / TEMPORAL_NAMESPACE env vars
- Spawns two Workers: orchestrator-tq and task-execution-tq
- Runs until cancelled (python -m activity_core.worker)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
57
src/activity_core/workflows.py
Normal file
57
src/activity_core/workflows.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Temporal workflow definitions for activity-core.
|
||||
|
||||
Two workflows are registered here:
|
||||
- RunActivityWorkflow → orchestrator-tq
|
||||
- TaskExecutorWorkflow → task-execution-tq
|
||||
|
||||
Workflow IDs follow the conventions in docs/conventions.md:
|
||||
RunActivityWorkflow: activity-{activity_id}:{trigger_key}
|
||||
TaskExecutorWorkflow: task-{run_id}:{task_type}:{index}
|
||||
|
||||
Implementations are added in T18–T19; stubs here let the worker
|
||||
register and the type system resolve references in T14–T17.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from temporalio import workflow
|
||||
|
||||
with workflow.unsafe.imports_passed_through():
|
||||
from activity_core.activities import (
|
||||
load_activity_definition,
|
||||
log_run,
|
||||
resolve_context,
|
||||
)
|
||||
|
||||
_DEFAULT_TIMEOUT = timedelta(minutes=5)
|
||||
|
||||
|
||||
@workflow.defn
|
||||
class RunActivityWorkflow:
|
||||
"""Durable orchestration workflow.
|
||||
|
||||
Sequence (T18):
|
||||
1. load_activity_definition(activity_id)
|
||||
2. resolve_context(context_sources)
|
||||
3. evaluate_templates(task_templates, context) ← pure function, no activity
|
||||
4. spawn TaskExecutorWorkflow child per template result
|
||||
5. log_run(...)
|
||||
"""
|
||||
|
||||
@workflow.run
|
||||
async def run(self, activity_id: str, trigger_key: str) -> dict:
|
||||
raise NotImplementedError("T18")
|
||||
|
||||
|
||||
@workflow.defn
|
||||
class TaskExecutorWorkflow:
|
||||
"""Child workflow that executes one concrete task instance.
|
||||
|
||||
Stub implementation in T19.
|
||||
"""
|
||||
|
||||
@workflow.run
|
||||
async def run(self, run_id: str, task_type: str, params: dict) -> dict:
|
||||
raise NotImplementedError("T19")
|
||||
Reference in New Issue
Block a user