30 lines
917 B
Python
30 lines
917 B
Python
"""Generic start → runner → complete/fail shell."""
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
from ..callback_client import StateCenterClient
|
|
from .errors import NodeError
|
|
from .payloads import build_complete_payload, build_fail_payload
|
|
|
|
Runner = Callable[[], dict[str, Any] | None]
|
|
|
|
|
|
def execute_node(
|
|
client: StateCenterClient,
|
|
job_id: str,
|
|
node_code: str,
|
|
runner: Runner,
|
|
*,
|
|
attempt_no: int = 1,
|
|
operator: str = "agent",
|
|
) -> dict[str, Any]:
|
|
client.start_node(job_id, node_code, attempt_no=attempt_no, operator=operator)
|
|
try:
|
|
output = runner() or {}
|
|
payload = build_complete_payload(job_id, node_code, attempt_no, output)
|
|
return client.complete_node(job_id, node_code, payload)
|
|
except NodeError as exc:
|
|
return client.fail_node(job_id, node_code, build_fail_payload(attempt_no, exc))
|