durable stopped workflow runs and resume
This commit is contained in:
@@ -10,8 +10,10 @@ from wf_core.runtime.ops.nodes import (
|
||||
from .engine import (
|
||||
execute_workflow,
|
||||
execute_workflow_async,
|
||||
execute_workflow_result_async,
|
||||
resume_workflow,
|
||||
resume_workflow_async,
|
||||
resume_workflow_result_async,
|
||||
)
|
||||
from .subgraphs import PreparedSubgraph
|
||||
from .step import complete_step, step_workflow, step_workflow_async
|
||||
@@ -26,8 +28,10 @@ __all__ = [
|
||||
"execute_node_use_async",
|
||||
"execute_workflow",
|
||||
"execute_workflow_async",
|
||||
"execute_workflow_result_async",
|
||||
"resume_workflow",
|
||||
"resume_workflow_async",
|
||||
"resume_workflow_result_async",
|
||||
"step_workflow",
|
||||
"step_workflow_async",
|
||||
"PreparedSubgraph",
|
||||
|
||||
@@ -70,6 +70,32 @@ async def execute_workflow_async(
|
||||
raise
|
||||
|
||||
|
||||
async def execute_workflow_result_async(
|
||||
workflow: Workflow,
|
||||
workflow_input: dict[str, Any],
|
||||
registry: Mapping[str, AsyncNodeHandler],
|
||||
*,
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
subgraphs: Mapping[str, PreparedSubgraph[AsyncNodeHandler]] | None = None,
|
||||
) -> RunState:
|
||||
"""Execute asynchronously and return failed state instead of raising failures."""
|
||||
run = create_run_state(workflow, workflow_input)
|
||||
|
||||
try:
|
||||
prepare_new_run(workflow, workflow_input, run)
|
||||
return await resume_workflow_async(
|
||||
workflow,
|
||||
run,
|
||||
registry,
|
||||
reducers=reducers,
|
||||
subgraphs=subgraphs,
|
||||
)
|
||||
except Exception as exc:
|
||||
run.status = RunStatus.FAILED
|
||||
run.error = str(exc)
|
||||
return run
|
||||
|
||||
|
||||
def resume_workflow(
|
||||
workflow: Workflow,
|
||||
run: RunState,
|
||||
@@ -174,6 +200,33 @@ async def resume_workflow_async(
|
||||
return finalize_run(workflow, run)
|
||||
|
||||
|
||||
async def resume_workflow_result_async(
|
||||
workflow: Workflow,
|
||||
run: RunState,
|
||||
registry: Mapping[str, AsyncNodeHandler],
|
||||
*,
|
||||
resume_payload: dict[str, Any] | None = None,
|
||||
resume_outcome: str = "submitted",
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
subgraphs: Mapping[str, PreparedSubgraph[AsyncNodeHandler]] | None = None,
|
||||
) -> RunState:
|
||||
"""Resume asynchronously and return failed state instead of raising failures."""
|
||||
try:
|
||||
return await resume_workflow_async(
|
||||
workflow,
|
||||
run,
|
||||
registry,
|
||||
resume_payload=resume_payload,
|
||||
resume_outcome=resume_outcome,
|
||||
reducers=reducers,
|
||||
subgraphs=subgraphs,
|
||||
)
|
||||
except Exception as exc:
|
||||
run.status = RunStatus.FAILED
|
||||
run.error = str(exc)
|
||||
return run
|
||||
|
||||
|
||||
def _interrupt_resume_target(
|
||||
root_workflow: Workflow,
|
||||
root_reducers: Mapping[str, ReducerDefinition] | None,
|
||||
|
||||
Reference in New Issue
Block a user