diff --git a/backend/app/tasks/downloads.py b/backend/app/tasks/downloads.py index 9185b04..235963b 100644 --- a/backend/app/tasks/downloads.py +++ b/backend/app/tasks/downloads.py @@ -5,7 +5,7 @@ import logging from datetime import datetime, timedelta from typing import Optional -from sqlalchemy import select, and_, or_ +from sqlalchemy import select, and_, or_, update from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker from sqlalchemy.orm import selectinload @@ -300,6 +300,16 @@ async def _download_source_async(source_id: int, download_id: int = None) -> dic source.error_count = 0 logger.info(f"Download completed for {subscription_name}/{source_platform}: {dl_result.files_downloaded} files") + # Mark any prior failures for this source as superseded + await session.execute( + update(Download) + .where( + Download.source_id == source_id, + Download.status == DownloadStatus.FAILED, + ) + .values(superseded=True) + ) + publish_event("download.completed", { "download_id": actual_download_id, "source_id": source_id,