|
|
@@ -4,7 +4,7 @@ import asyncio
|
|
|
import json
|
|
|
import logging
|
|
|
import zipfile
|
|
|
-from datetime import datetime, timedelta
|
|
|
+from datetime import datetime
|
|
|
from pathlib import Path
|
|
|
|
|
|
import defusedxml.ElementTree as ET
|
|
|
@@ -862,27 +862,6 @@ class PrintScheduler:
|
|
|
await self._power_off_if_needed(db, item)
|
|
|
return
|
|
|
|
|
|
- # Safety: Check if this archive was printed recently (within 4 hours)
|
|
|
- # This prevents phantom reprints if a queue item got stuck in "pending"
|
|
|
- # after its print already started due to a crash/restart
|
|
|
- if archive.status == "completed" and archive.completed_at:
|
|
|
- completed_at = (
|
|
|
- archive.completed_at.replace(tzinfo=None) if archive.completed_at.tzinfo else archive.completed_at
|
|
|
- )
|
|
|
- time_since_completed = datetime.utcnow() - completed_at
|
|
|
- if time_since_completed < timedelta(hours=4):
|
|
|
- logger.warning(
|
|
|
- f"Queue item {item.id}: Archive {item.archive_id} was already printed "
|
|
|
- f"{time_since_completed.total_seconds() / 3600:.1f} hours ago, skipping to prevent duplicate"
|
|
|
- )
|
|
|
- item.status = "skipped"
|
|
|
- item.error_message = (
|
|
|
- f"Archive was already printed {time_since_completed.total_seconds() / 3600:.1f} hours ago"
|
|
|
- )
|
|
|
- item.completed_at = datetime.utcnow()
|
|
|
- await db.commit()
|
|
|
- return
|
|
|
-
|
|
|
file_path = settings.base_dir / archive.file_path
|
|
|
filename = archive.filename
|
|
|
|