generated from coulomb/repo-seed
feat(WP-0002): complete Triggers & Ops workstream
Delivers all 12 tasks (T22–T33): Temporal Schedule manager + startup sync, NATS JetStream event router, FastAPI CRUD + manual trigger, Prometheus metrics wiring, custom search-attribute tagging, and operational runbook. Marks workplan status as done. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,23 +4,31 @@ Starts two workers (wired up in T20):
|
||||
- orchestrator-tq: RunActivityWorkflow + its activities
|
||||
- task-execution-tq: TaskExecutorWorkflow
|
||||
|
||||
T23: Calls sync_schedules before entering the worker run loop to ensure
|
||||
all cron ActivityDefinitions have live Temporal Schedules.
|
||||
|
||||
T31: Exposes Prometheus metrics via the Temporal SDK runtime on :9090/metrics.
|
||||
|
||||
Run with:
|
||||
TEMPORAL_HOST=localhost:7233 \
|
||||
ACTCORE_DB_URL=postgresql+asyncpg://actcore:actcore@localhost:5433/actcore \
|
||||
python -m activity_core.worker
|
||||
|
||||
Environment variables:
|
||||
TEMPORAL_HOST Temporal frontend address (default: localhost:7233)
|
||||
TEMPORAL_NAMESPACE Temporal namespace (default: default)
|
||||
ACTCORE_DB_URL App DB connection string (required)
|
||||
TEMPORAL_HOST Temporal frontend address (default: localhost:7233)
|
||||
TEMPORAL_NAMESPACE Temporal namespace (default: default)
|
||||
ACTCORE_DB_URL App DB connection string (required)
|
||||
PROMETHEUS_BIND_ADDR Prometheus metrics bind (default: 0.0.0.0:9090)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
|
||||
from temporalio.client import Client
|
||||
from temporalio.runtime import PrometheusConfig, Runtime, TelemetryConfig
|
||||
from temporalio.worker import Worker
|
||||
|
||||
from activity_core.activities import (
|
||||
@@ -30,10 +38,14 @@ from activity_core.activities import (
|
||||
persist_task_instance,
|
||||
resolve_context,
|
||||
)
|
||||
from activity_core.sync_schedules import sync as sync_schedules
|
||||
from activity_core.workflows import RunActivityWorkflow, TaskExecutorWorkflow
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TEMPORAL_HOST = os.environ.get("TEMPORAL_HOST", "localhost:7233")
|
||||
TEMPORAL_NAMESPACE = os.environ.get("TEMPORAL_NAMESPACE", "default")
|
||||
PROMETHEUS_BIND_ADDR = os.environ.get("PROMETHEUS_BIND_ADDR", "0.0.0.0:9090")
|
||||
|
||||
ORCHESTRATOR_TASK_QUEUE = "orchestrator-tq"
|
||||
TASK_EXECUTION_TASK_QUEUE = "task-execution-tq"
|
||||
@@ -45,7 +57,23 @@ async def run() -> None:
|
||||
raise RuntimeError("ACTCORE_DB_URL is required")
|
||||
init_session_factory(db_url)
|
||||
|
||||
client = await Client.connect(TEMPORAL_HOST, namespace=TEMPORAL_NAMESPACE)
|
||||
# T31: Configure the Temporal SDK runtime to emit metrics in Prometheus format.
|
||||
runtime = Runtime(
|
||||
telemetry=TelemetryConfig(
|
||||
metrics=PrometheusConfig(bind_address=PROMETHEUS_BIND_ADDR)
|
||||
)
|
||||
)
|
||||
|
||||
client = await Client.connect(
|
||||
TEMPORAL_HOST, namespace=TEMPORAL_NAMESPACE, runtime=runtime
|
||||
)
|
||||
|
||||
# T23: Sync Temporal Schedules with the DB before workers start accepting tasks.
|
||||
logger.info("Syncing Temporal Schedules with ActivityDefinition DB...")
|
||||
try:
|
||||
await sync_schedules(client, db_url)
|
||||
except Exception:
|
||||
logger.exception("schedule sync failed — continuing worker startup")
|
||||
|
||||
orchestrator_worker = Worker(
|
||||
client,
|
||||
@@ -70,4 +98,5 @@ async def run() -> None:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
asyncio.run(run())
|
||||
|
||||
Reference in New Issue
Block a user