feat: add graph workflow fallback and retry metadata
This commit is contained in:
@@ -220,6 +220,129 @@ async def test_dispatch_render_with_workflow_falls_back_when_workflow_runtime_pr
|
||||
assert runs == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dispatch_render_with_workflow_graph_mode_dispatches_supported_custom_workflow(
|
||||
db,
|
||||
admin_user,
|
||||
monkeypatch,
|
||||
tmp_path,
|
||||
):
|
||||
_use_test_database(monkeypatch)
|
||||
order_line = await _seed_renderable_order_line(db, admin_user, tmp_path)
|
||||
workflow_definition = WorkflowDefinition(
|
||||
name=f"Graph Workflow {uuid.uuid4().hex[:8]}",
|
||||
output_type_id=order_line.output_type_id,
|
||||
config={
|
||||
"version": 1,
|
||||
"ui": {"preset": "custom", "execution_mode": "graph"},
|
||||
"nodes": [
|
||||
{"id": "setup", "step": "order_line_setup", "params": {}},
|
||||
{"id": "template", "step": "resolve_template", "params": {}},
|
||||
{"id": "render", "step": "blender_still", "params": {"width": 1024, "height": 768}},
|
||||
],
|
||||
"edges": [
|
||||
{"from": "setup", "to": "template"},
|
||||
{"from": "template", "to": "render"},
|
||||
],
|
||||
},
|
||||
is_active=True,
|
||||
)
|
||||
db.add(workflow_definition)
|
||||
await db.flush()
|
||||
output_type = await db.get(OutputType, order_line.output_type_id)
|
||||
assert output_type is not None
|
||||
output_type.workflow_definition_id = workflow_definition.id
|
||||
await db.commit()
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.tasks.celery_app.celery_app.send_task",
|
||||
lambda task_name, args, kwargs: type("Result", (), {"id": "graph-task-1"})(),
|
||||
)
|
||||
|
||||
result = dispatch_render_with_workflow(str(order_line.id))
|
||||
|
||||
await db.rollback()
|
||||
|
||||
run_result = await db.execute(
|
||||
select(WorkflowRun)
|
||||
.where(WorkflowRun.id == uuid.UUID(result["workflow_run_id"]))
|
||||
.options(selectinload(WorkflowRun.node_results))
|
||||
)
|
||||
run = run_result.scalar_one()
|
||||
node_results = {node_result.node_name: node_result for node_result in run.node_results}
|
||||
|
||||
assert result["backend"] == "workflow_graph"
|
||||
assert result["execution_mode"] == "graph"
|
||||
assert result["task_ids"] == ["graph-task-1"]
|
||||
assert run.status == "pending"
|
||||
assert node_results["setup"].status == "completed"
|
||||
assert node_results["template"].status == "completed"
|
||||
assert node_results["render"].status == "queued"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dispatch_render_with_workflow_graph_mode_falls_back_to_legacy_on_graph_failure(
|
||||
db,
|
||||
admin_user,
|
||||
monkeypatch,
|
||||
tmp_path,
|
||||
):
|
||||
_use_test_database(monkeypatch)
|
||||
order_line = await _seed_renderable_order_line(db, admin_user, tmp_path)
|
||||
workflow_definition = WorkflowDefinition(
|
||||
name=f"Graph Workflow {uuid.uuid4().hex[:8]}",
|
||||
output_type_id=order_line.output_type_id,
|
||||
config={
|
||||
"version": 1,
|
||||
"ui": {"preset": "custom", "execution_mode": "graph"},
|
||||
"nodes": [
|
||||
{
|
||||
"id": "setup",
|
||||
"step": "order_line_setup",
|
||||
"params": {"failure_policy": {"fallback_to_legacy": True}},
|
||||
},
|
||||
{"id": "render", "step": "blender_still", "params": {"width": 1024, "height": 768}},
|
||||
],
|
||||
"edges": [
|
||||
{"from": "setup", "to": "render"},
|
||||
],
|
||||
},
|
||||
is_active=True,
|
||||
)
|
||||
db.add(workflow_definition)
|
||||
await db.flush()
|
||||
output_type = await db.get(OutputType, order_line.output_type_id)
|
||||
assert output_type is not None
|
||||
output_type.workflow_definition_id = workflow_definition.id
|
||||
await db.commit()
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.domains.rendering.workflow_graph_runtime.execute_graph_workflow",
|
||||
lambda *_args, **_kwargs: (_ for _ in ()).throw(RuntimeError("graph dispatch exploded")),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"app.domains.rendering.dispatch_service._legacy_dispatch",
|
||||
lambda order_line_id: {"backend": "legacy", "order_line_id": order_line_id},
|
||||
)
|
||||
|
||||
result = dispatch_render_with_workflow(str(order_line.id))
|
||||
|
||||
await db.rollback()
|
||||
|
||||
runs = (
|
||||
await db.execute(
|
||||
select(WorkflowRun).options(selectinload(WorkflowRun.node_results)).order_by(WorkflowRun.created_at.desc())
|
||||
)
|
||||
).scalars().all()
|
||||
run = runs[0]
|
||||
|
||||
assert result["backend"] == "legacy"
|
||||
assert result["fallback_from"] == "workflow_graph"
|
||||
assert result["workflow_run_id"] == str(run.id)
|
||||
assert run.status == "failed"
|
||||
assert run.error_message == "graph dispatch exploded"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_workflow_dispatch_endpoint_returns_workflow_run_with_node_results(
|
||||
client,
|
||||
|
||||
Reference in New Issue
Block a user