feat: voortgang copy/duplicate/move in headerbar
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -119,6 +119,27 @@ class HistoryRepository:
|
||||
),
|
||||
)
|
||||
|
||||
def reconcile_entries_failed(
|
||||
self,
|
||||
entry_ids: list[str],
|
||||
*,
|
||||
error_code: str = "task_interrupted",
|
||||
error_message: str = "Task was interrupted before completion",
|
||||
) -> None:
|
||||
if not entry_ids:
|
||||
return
|
||||
finished_at = self._now_iso()
|
||||
placeholders = ", ".join("?" for _ in entry_ids)
|
||||
with self._connection() as conn:
|
||||
conn.execute(
|
||||
f"""
|
||||
UPDATE history
|
||||
SET status = ?, error_code = ?, error_message = ?, finished_at = ?
|
||||
WHERE id IN ({placeholders})
|
||||
""",
|
||||
("failed", error_code, error_message, finished_at, *entry_ids),
|
||||
)
|
||||
|
||||
def _ensure_schema(self) -> None:
|
||||
db_path = Path(self._db_path)
|
||||
if db_path.parent and str(db_path.parent) not in {"", "."}:
|
||||
|
||||
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
|
||||
VALID_STATUSES = {"queued", "running", "completed", "failed", "requested", "preparing", "ready", "cancelled"}
|
||||
VALID_OPERATIONS = {"copy", "move", "download", "duplicate"}
|
||||
NON_TERMINAL_STATUSES = ("queued", "running", "requested", "preparing")
|
||||
TASK_MIGRATION_COLUMNS: dict[str, str] = {
|
||||
"operation": "TEXT NOT NULL DEFAULT 'copy'",
|
||||
"status": "TEXT NOT NULL DEFAULT 'queued'",
|
||||
@@ -394,6 +395,44 @@ class TaskRepository:
|
||||
with self._connection() as conn:
|
||||
conn.execute("DELETE FROM task_artifacts WHERE task_id = ?", (task_id,))
|
||||
|
||||
def reconcile_incomplete_tasks(
|
||||
self,
|
||||
*,
|
||||
error_code: str = "task_interrupted",
|
||||
error_message: str = "Task was interrupted before completion",
|
||||
) -> list[str]:
|
||||
finished_at = self._now_iso()
|
||||
placeholders = ", ".join("?" for _ in NON_TERMINAL_STATUSES)
|
||||
with self._connection() as conn:
|
||||
rows = conn.execute(
|
||||
f"""
|
||||
SELECT id
|
||||
FROM tasks
|
||||
WHERE status IN ({placeholders})
|
||||
""",
|
||||
NON_TERMINAL_STATUSES,
|
||||
).fetchall()
|
||||
task_ids = [row["id"] for row in rows]
|
||||
if not task_ids:
|
||||
return []
|
||||
task_placeholders = ", ".join("?" for _ in task_ids)
|
||||
conn.execute(
|
||||
f"""
|
||||
UPDATE tasks
|
||||
SET status = ?, finished_at = ?, error_code = ?, error_message = ?, current_item = NULL
|
||||
WHERE id IN ({task_placeholders})
|
||||
""",
|
||||
("failed", finished_at, error_code, error_message, *task_ids),
|
||||
)
|
||||
conn.execute(
|
||||
f"""
|
||||
DELETE FROM task_artifacts
|
||||
WHERE task_id IN ({task_placeholders})
|
||||
""",
|
||||
task_ids,
|
||||
)
|
||||
return task_ids
|
||||
|
||||
def _migrate_tasks_columns(self, conn: sqlite3.Connection) -> None:
|
||||
rows = conn.execute("PRAGMA table_info(tasks)").fetchall()
|
||||
existing_columns = {row["name"] for row in rows}
|
||||
|
||||
Reference in New Issue
Block a user