feat: B3 uit voor veilige archive-downloads - cancel knop toegevoegd
This commit is contained in:
@@ -6,7 +6,7 @@ from contextlib import contextmanager
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
VALID_STATUSES = {"queued", "running", "completed", "failed", "requested", "preparing", "ready"}
|
||||
VALID_STATUSES = {"queued", "running", "completed", "failed", "requested", "preparing", "ready", "cancelled"}
|
||||
VALID_OPERATIONS = {"copy", "move", "download"}
|
||||
TASK_MIGRATION_COLUMNS: dict[str, str] = {
|
||||
"operation": "TEXT NOT NULL DEFAULT 'copy'",
|
||||
@@ -160,17 +160,18 @@ class TaskRepository:
|
||||
done_items: int | None = None,
|
||||
total_items: int | None = None,
|
||||
current_item: str | None = None,
|
||||
) -> None:
|
||||
) -> bool:
|
||||
started_at = self._now_iso()
|
||||
with self._connection() as conn:
|
||||
conn.execute(
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE tasks
|
||||
SET status = ?, started_at = COALESCE(started_at, ?), done_items = ?, total_items = ?, current_item = ?
|
||||
WHERE id = ?
|
||||
WHERE id = ? AND status = ?
|
||||
""",
|
||||
("preparing", started_at, done_items, total_items, current_item, task_id),
|
||||
("preparing", started_at, done_items, total_items, current_item, task_id, "requested"),
|
||||
)
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def update_progress(
|
||||
self,
|
||||
@@ -215,17 +216,18 @@ class TaskRepository:
|
||||
task_id: str,
|
||||
done_items: int | None = None,
|
||||
total_items: int | None = None,
|
||||
) -> None:
|
||||
) -> bool:
|
||||
finished_at = self._now_iso()
|
||||
with self._connection() as conn:
|
||||
conn.execute(
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE tasks
|
||||
SET status = ?, finished_at = ?, done_items = ?, total_items = ?, current_item = NULL
|
||||
WHERE id = ?
|
||||
WHERE id = ? AND status = ?
|
||||
""",
|
||||
("ready", finished_at, done_items, total_items, task_id),
|
||||
("ready", finished_at, done_items, total_items, task_id, "preparing"),
|
||||
)
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def mark_failed(
|
||||
self,
|
||||
@@ -260,6 +262,54 @@ class TaskRepository:
|
||||
),
|
||||
)
|
||||
|
||||
def mark_failed_if_not_cancelled(
|
||||
self,
|
||||
task_id: str,
|
||||
error_code: str,
|
||||
error_message: str,
|
||||
failed_item: str | None,
|
||||
done_bytes: int | None,
|
||||
total_bytes: int | None,
|
||||
done_items: int | None = None,
|
||||
total_items: int | None = None,
|
||||
) -> bool:
|
||||
finished_at = self._now_iso()
|
||||
with self._connection() as conn:
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE tasks
|
||||
SET status = ?, finished_at = ?, error_code = ?, error_message = ?, failed_item = ?, done_bytes = ?, total_bytes = ?, done_items = ?, total_items = ?, current_item = NULL
|
||||
WHERE id = ? AND status != ?
|
||||
""",
|
||||
(
|
||||
"failed",
|
||||
finished_at,
|
||||
error_code,
|
||||
error_message,
|
||||
failed_item,
|
||||
done_bytes,
|
||||
total_bytes,
|
||||
done_items,
|
||||
total_items,
|
||||
task_id,
|
||||
"cancelled",
|
||||
),
|
||||
)
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def mark_cancelled(self, task_id: str) -> bool:
|
||||
finished_at = self._now_iso()
|
||||
with self._connection() as conn:
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE tasks
|
||||
SET status = ?, finished_at = ?, current_item = NULL
|
||||
WHERE id = ? AND status IN (?, ?)
|
||||
""",
|
||||
("cancelled", finished_at, task_id, "requested", "preparing"),
|
||||
)
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def _ensure_schema(self) -> None:
|
||||
db_path = Path(self._db_path)
|
||||
if db_path.parent and str(db_path.parent) not in {"", "."}:
|
||||
|
||||
Reference in New Issue
Block a user