diff --git a/py/routes/handlers/model_handlers.py b/py/routes/handlers/model_handlers.py index 1340ee07..0f53d096 100644 --- a/py/routes/handlers/model_handlers.py +++ b/py/routes/handlers/model_handlers.py @@ -1785,6 +1785,8 @@ class ModelDownloadHandler: bytes_downloaded = 0 total_bytes_raw = request.query.get("total_bytes") total_bytes = int(total_bytes_raw) if total_bytes_raw else None + completed_at_raw = request.query.get("completed_at") + completed_at = float(completed_at_raw) if completed_at_raw else None service = await DownloadQueueService.get_instance() item = await service.complete_download( @@ -1794,6 +1796,7 @@ class ModelDownloadHandler: file_path=file_path, bytes_downloaded=bytes_downloaded, total_bytes=total_bytes, + completed_at=completed_at, ) if item is None: return web.json_response( diff --git a/py/services/download_queue_service.py b/py/services/download_queue_service.py index 243bf295..1aaf70bc 100644 --- a/py/services/download_queue_service.py +++ b/py/services/download_queue_service.py @@ -349,6 +349,7 @@ class DownloadQueueService: file_path: Optional[str] = None, bytes_downloaded: int = 0, total_bytes: Optional[int] = None, + completed_at: Optional[float] = None, ) -> Optional[dict[str, Any]]: """Atomically move a download from the queue into the history table. @@ -356,6 +357,9 @@ class DownloadQueueService: queue, and inserts a corresponding history entry with the given terminal status (``completed``, ``failed``, or ``canceled``). + When *completed_at* is provided it is used as the completion + timestamp; otherwise ``time.time()`` is used. + Returns the original queue record (before deletion) on success, or ``None`` if the download was not found in the queue. """ @@ -368,7 +372,7 @@ class DownloadQueueService: if row is None: return None - now = time.time() + now = completed_at if completed_at is not None else time.time() conn.execute( "DELETE FROM download_queue WHERE download_id = ?", (download_id,),