Add reusable dry-run execution controls

This commit is contained in:
ajp_anton
2026-08-16 01:51:21 +00:00
parent 58b4f69d63
commit 531992fe47
3 changed files with 111 additions and 2 deletions
+41
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import ipaddress
import json
from datetime import datetime
from pathlib import Path
@@ -135,13 +136,53 @@ def create_app(settings: Settings | None = None) -> Flask:
run = store.get(run_id)
if run is None:
abort(404)
execution_task = execution_replay_task(run)
return render_template(
"run.html",
run=run,
children=store.children(run.id),
output=read_run_output(run),
execution_task=execution_task,
)
def execution_replay_task(run):
if run.status != "succeeded" or run.target_kind != "task":
return None
task = catalog.task(run.target_path)
if task is None or task.execution is None:
return None
if any(field.type == "file" or field.sensitive for field in task.inputs):
return None
try:
input_data = json.loads(run.input_json)
except json.JSONDecodeError:
return None
if not isinstance(input_data, dict):
return None
if input_data.get(task.execution.field.name) != task.execution.dry_run_value:
return None
return task
@app.post("/runs/<int:run_id>/execute")
def execute_dry_run(run_id: int):
run = store.get(run_id)
if run is None:
abort(404)
task = execution_replay_task(run)
if task is None:
abort(404)
input_data = json.loads(run.input_json)
input_data[task.execution.field.name] = task.execution.execute_value
raw_values = {
name: [str(value) for value in value] if isinstance(value, list) else [str(value)]
for name, value in input_data.items()
}
validated, errors = validate_inputs(task.inputs, raw_values)
if errors:
abort(409)
executed, _ = manager.run_task(task, validated)
return redirect(url_for("run_detail", run_id=executed.id))
@app.post("/runs/<int:run_id>/cancel")
def cancel_run(run_id: int):
run = manager.request_cancel(run_id)