Fix backfill limit for skipped archives
This commit is contained in:
@@ -56,6 +56,8 @@ Run a test with one archive first:
|
|||||||
curl.exe -X POST -H "X-Service-Token: change-me" "http://localhost:8088/sync/backfill?max_archives=1"
|
curl.exe -X POST -H "X-Service-Token: change-me" "http://localhost:8088/sync/backfill?max_archives=1"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When `SYNC_SUCCESS_ONLY=true`, `max_archives` counts import attempts. Archives that are still `printing` or already failed are skipped and do not consume the limit.
|
||||||
|
|
||||||
Run full backfill for successful Bambuddy archives:
|
Run full backfill for successful Bambuddy archives:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ class ArchiveSyncService:
|
|||||||
|
|
||||||
async def backfill(self, *, status: str | None = None, max_archives: int | None = None) -> dict[str, int]:
|
async def backfill(self, *, status: str | None = None, max_archives: int | None = None) -> dict[str, int]:
|
||||||
status_filter = status
|
status_filter = status
|
||||||
if status_filter is None and self.settings.sync_success_only:
|
target_status = status.lower() if status else None
|
||||||
status_filter = "success"
|
|
||||||
|
|
||||||
counts = {"seen": 0, "synced": 0, "already_synced": 0, "skipped": 0, "failed": 0}
|
counts = {"seen": 0, "synced": 0, "already_synced": 0, "skipped": 0, "failed": 0}
|
||||||
offset = 0
|
offset = 0
|
||||||
@@ -83,7 +82,10 @@ class ArchiveSyncService:
|
|||||||
break
|
break
|
||||||
|
|
||||||
for archive in archives:
|
for archive in archives:
|
||||||
if max_archives is not None and counts["seen"] >= max_archives:
|
if target_status and (archive.status or "").lower() != target_status:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if max_archives is not None and self._backfill_limit_reached(counts, max_archives):
|
||||||
return counts
|
return counts
|
||||||
|
|
||||||
counts["seen"] += 1
|
counts["seen"] += 1
|
||||||
@@ -94,6 +96,9 @@ class ArchiveSyncService:
|
|||||||
logger.exception("Failed to sync Bambuddy archive %s during backfill", archive.id)
|
logger.exception("Failed to sync Bambuddy archive %s during backfill", archive.id)
|
||||||
counts["failed"] += 1
|
counts["failed"] += 1
|
||||||
|
|
||||||
|
if max_archives is not None and self._backfill_limit_reached(counts, max_archives):
|
||||||
|
return counts
|
||||||
|
|
||||||
offset += len(archives)
|
offset += len(archives)
|
||||||
if total is not None and offset >= total:
|
if total is not None and offset >= total:
|
||||||
break
|
break
|
||||||
@@ -274,3 +279,7 @@ class ArchiveSyncService:
|
|||||||
if status in {"success", "completed", "complete", "done"}:
|
if status in {"success", "completed", "complete", "done"}:
|
||||||
return True
|
return True
|
||||||
return bool(archive.completed_at and status not in {"failed", "stopped", "printing", "running"})
|
return bool(archive.completed_at and status not in {"failed", "stopped", "printing", "running"})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _backfill_limit_reached(counts: dict[str, int], max_archives: int) -> bool:
|
||||||
|
return counts["synced"] + counts["already_synced"] + counts["failed"] >= max_archives
|
||||||
|
|||||||
Reference in New Issue
Block a user