feat: add wf source resource refs
This commit is contained in:
@@ -51,6 +51,7 @@ async def execute_workflow_async(
|
||||
*,
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
subgraphs: Mapping[str, PreparedSubgraph[AsyncNodeHandler]] | None = None,
|
||||
platform: object | None = None,
|
||||
) -> RunState:
|
||||
"""Create a run and execute a workflow asynchronously until it stops."""
|
||||
run = create_run_state(workflow, workflow_input)
|
||||
@@ -63,6 +64,7 @@ async def execute_workflow_async(
|
||||
registry,
|
||||
reducers=reducers,
|
||||
subgraphs=subgraphs,
|
||||
platform=platform,
|
||||
)
|
||||
except Exception as exc:
|
||||
run.status = RunStatus.FAILED
|
||||
@@ -77,6 +79,7 @@ async def execute_workflow_result_async(
|
||||
*,
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
subgraphs: Mapping[str, PreparedSubgraph[AsyncNodeHandler]] | None = None,
|
||||
platform: object | None = None,
|
||||
) -> RunState:
|
||||
"""Execute asynchronously and return failed state instead of raising failures."""
|
||||
run = create_run_state(workflow, workflow_input)
|
||||
@@ -89,6 +92,7 @@ async def execute_workflow_result_async(
|
||||
registry,
|
||||
reducers=reducers,
|
||||
subgraphs=subgraphs,
|
||||
platform=platform,
|
||||
)
|
||||
except Exception as exc:
|
||||
run.status = RunStatus.FAILED
|
||||
@@ -157,6 +161,7 @@ async def resume_workflow_async(
|
||||
resume_outcome: str = "submitted",
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
subgraphs: Mapping[str, PreparedSubgraph[AsyncNodeHandler]] | None = None,
|
||||
platform: object | None = None,
|
||||
) -> RunState:
|
||||
"""Resume an async run from its current state."""
|
||||
interrupted_workflow, interrupted_reducers = _interrupt_resume_target(
|
||||
@@ -193,6 +198,7 @@ async def resume_workflow_async(
|
||||
index=index if frame.scope_id == ROOT_SCOPE_ID else None,
|
||||
reducers=active_reducers,
|
||||
subgraphs=subgraphs,
|
||||
platform=platform,
|
||||
)
|
||||
if run.status == RunStatus.INTERRUPTED:
|
||||
return run
|
||||
@@ -209,6 +215,7 @@ async def resume_workflow_result_async(
|
||||
resume_outcome: str = "submitted",
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
subgraphs: Mapping[str, PreparedSubgraph[AsyncNodeHandler]] | None = None,
|
||||
platform: object | None = None,
|
||||
) -> RunState:
|
||||
"""Resume asynchronously and return failed state instead of raising failures."""
|
||||
try:
|
||||
@@ -220,6 +227,7 @@ async def resume_workflow_result_async(
|
||||
resume_outcome=resume_outcome,
|
||||
reducers=reducers,
|
||||
subgraphs=subgraphs,
|
||||
platform=platform,
|
||||
)
|
||||
except Exception as exc:
|
||||
run.status = RunStatus.FAILED
|
||||
|
||||
@@ -55,6 +55,7 @@ def _resolve_node_execution(
|
||||
frame: ExecutionFrame,
|
||||
node: NodeUse,
|
||||
node_def: NodeDef,
|
||||
platform: object | None = None,
|
||||
) -> tuple[dict[str, Any], RuntimeContext, dict[str, Any]]:
|
||||
context_values = frame_context_values(frame)
|
||||
state_view = state_view_for_frame(run, frame)
|
||||
@@ -90,6 +91,7 @@ def _resolve_node_execution(
|
||||
prior_outcome=frame.prior_outcome,
|
||||
activated_incoming_edge=frame.activated_incoming_edge,
|
||||
metadata=dict(frame.metadata),
|
||||
platform=platform,
|
||||
)
|
||||
return resolved_input, context, state_view
|
||||
|
||||
@@ -200,6 +202,7 @@ async def execute_node_use_async(
|
||||
node_def: NodeDef,
|
||||
registry: Mapping[str, AsyncNodeHandler],
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
platform: object | None = None,
|
||||
) -> StepExecutionResult:
|
||||
handler = registry.get(node.node)
|
||||
if handler is None:
|
||||
@@ -214,6 +217,7 @@ async def execute_node_use_async(
|
||||
frame=frame,
|
||||
node=node,
|
||||
node_def=node_def,
|
||||
platform=platform,
|
||||
)
|
||||
raw_or_awaitable = handler(resolved_input, context)
|
||||
if isinstance(raw_or_awaitable, Awaitable):
|
||||
@@ -240,6 +244,7 @@ async def invoke_node_use_async_for_frame(
|
||||
node: NodeUse,
|
||||
node_def: NodeDef,
|
||||
registry: Mapping[str, AsyncNodeHandler],
|
||||
platform: object | None = None,
|
||||
) -> PendingAsyncNodeResult:
|
||||
"""Resolve input, await the async handler, and defer state finalization.
|
||||
|
||||
@@ -258,6 +263,7 @@ async def invoke_node_use_async_for_frame(
|
||||
frame=frame,
|
||||
node=node,
|
||||
node_def=node_def,
|
||||
platform=platform,
|
||||
)
|
||||
raw_or_awaitable = handler(resolved_input, context)
|
||||
if isinstance(raw_or_awaitable, Awaitable):
|
||||
@@ -302,6 +308,7 @@ async def execute_node_use_async_for_frame(
|
||||
node_def: NodeDef,
|
||||
registry: Mapping[str, AsyncNodeHandler],
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
platform: object | None = None,
|
||||
) -> StepExecutionResult:
|
||||
"""Execute one async node against an explicit frame.
|
||||
|
||||
@@ -316,6 +323,7 @@ async def execute_node_use_async_for_frame(
|
||||
node=node,
|
||||
node_def=node_def,
|
||||
registry=registry,
|
||||
platform=platform,
|
||||
)
|
||||
return finalize_pending_async_node_result(
|
||||
workflow=workflow,
|
||||
|
||||
@@ -216,6 +216,7 @@ async def step_workflow_async(
|
||||
index: WorkflowIndex | None = None,
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
subgraphs: Mapping[str, PreparedSubgraph[AsyncNodeHandler]] | None = None,
|
||||
platform: object | None = None,
|
||||
) -> RunState:
|
||||
"""Execute at most one async workflow step."""
|
||||
frame = run.current_frame() if run.current_frame_id is not None else None
|
||||
@@ -232,6 +233,7 @@ async def step_workflow_async(
|
||||
index=resolved_index,
|
||||
reducers=reducers,
|
||||
first_frame=frame,
|
||||
platform=platform,
|
||||
)
|
||||
prepared = prepare_step(workflow, run, resolved_index)
|
||||
if prepared is None:
|
||||
@@ -249,6 +251,7 @@ async def step_workflow_async(
|
||||
node_def,
|
||||
registry,
|
||||
reducers=reducers,
|
||||
platform=platform,
|
||||
)
|
||||
except Exception as exc:
|
||||
if _mark_handled_item_failure(run, index, frame, exc):
|
||||
@@ -303,6 +306,7 @@ async def _step_async_foreach_item_batch(
|
||||
index: WorkflowIndex,
|
||||
first_frame: ExecutionFrame,
|
||||
reducers: Mapping[str, ReducerDefinition] | None,
|
||||
platform: object | None = None,
|
||||
) -> RunState:
|
||||
"""Run one batch of ready concurrent-foreach item node handlers.
|
||||
|
||||
@@ -322,6 +326,7 @@ async def _step_async_foreach_item_batch(
|
||||
node,
|
||||
index.node_defs[node.node],
|
||||
registry,
|
||||
platform=platform,
|
||||
)
|
||||
)
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
Reference in New Issue
Block a user