Add typed task input forms

This commit is contained in:
ajp_anton
2026-08-08 18:39:09 +00:00
parent 56d6194324
commit 0549ed1b0d
8 changed files with 521 additions and 16 deletions
+20 -6
View File
@@ -3,6 +3,8 @@
from __future__ import annotations
import sqlite3
import json
from collections.abc import Mapping
from dataclasses import dataclass
from datetime import UTC, datetime
from pathlib import Path
@@ -27,6 +29,7 @@ class Run:
parent_run_id: int | None
log_path: str | None
message: str | None
input_json: str
def now() -> str:
@@ -56,10 +59,19 @@ class RunStore:
cancel_requested_at TEXT,
parent_run_id INTEGER REFERENCES runs(id),
log_path TEXT,
message TEXT
message TEXT,
input_json TEXT NOT NULL DEFAULT '{}'
)
"""
)
columns = {
row["name"]
for row in connection.execute("PRAGMA table_info(runs)").fetchall()
}
if "input_json" not in columns:
connection.execute(
"ALTER TABLE runs ADD COLUMN input_json TEXT NOT NULL DEFAULT '{}'"
)
connection.execute(
"""
CREATE INDEX IF NOT EXISTS runs_queue_index
@@ -93,7 +105,9 @@ class RunStore:
target_path: str,
queue_group: str,
trigger: str = "manual",
input_data: Mapping[str, str | int | list[str]] | None = None,
) -> tuple[Run, bool]:
input_json = json.dumps(input_data or {}, sort_keys=True, separators=(",", ":"))
with self._connect() as connection:
connection.execute("BEGIN IMMEDIATE")
existing = connection.execute(
@@ -112,10 +126,10 @@ class RunStore:
cursor = connection.execute(
"""
INSERT INTO runs (
target_kind, target_path, queue_group, trigger, status, created_at
) VALUES (?, ?, ?, ?, 'queued', ?)
target_kind, target_path, queue_group, trigger, status, created_at, input_json
) VALUES (?, ?, ?, ?, 'queued', ?, ?)
""",
(target_kind, target_path, queue_group, trigger, now()),
(target_kind, target_path, queue_group, trigger, now(), input_json),
)
return self.get(cursor.lastrowid, connection=connection), True
@@ -146,8 +160,8 @@ class RunStore:
"""
INSERT INTO runs (
target_kind, target_path, queue_group, trigger, status, created_at,
started_at, parent_run_id
) VALUES ('task', ?, ?, ?, 'running', ?, ?, ?)
started_at, parent_run_id, input_json
) VALUES ('task', ?, ?, ?, 'running', ?, ?, ?, '{}')
""",
(
task_path,