|
|
@@ -2119,40 +2119,46 @@ async def on_print_complete(printer_id: int, data: dict):
|
|
|
# auto-start files found in root on power cycle, causing ghost prints.
|
|
|
# Must run before the archive_id early-return so it executes even when archiving is disabled.
|
|
|
try:
|
|
|
- printer_info = printer_manager.get_printer(printer_id)
|
|
|
- if printer_info and subtask_name:
|
|
|
- from backend.app.services.bambu_ftp import delete_file_async
|
|
|
-
|
|
|
- # Try both .3mf and .gcode extensions — the printer may have either
|
|
|
- for ext in (".3mf", ".gcode"):
|
|
|
- remote_path = f"/{subtask_name}{ext}"
|
|
|
- # Retry up to 3 times — the printer may still lock the filesystem briefly after a print ends
|
|
|
- for attempt in range(1, 4):
|
|
|
- try:
|
|
|
- delete_result = await delete_file_async(
|
|
|
- printer_info.ip_address,
|
|
|
- printer_info.access_code,
|
|
|
- remote_path,
|
|
|
- printer_model=printer_info.model,
|
|
|
- )
|
|
|
- if delete_result:
|
|
|
- logger.info("Deleted %s from printer %s SD card", remote_path, printer_info.name)
|
|
|
- break # Success or file doesn't exist — no need to retry
|
|
|
- except Exception as e:
|
|
|
- if attempt < 3:
|
|
|
- logger.debug(
|
|
|
- "SD card cleanup attempt %d/3 failed for %s: %s, retrying in 2s",
|
|
|
- attempt,
|
|
|
- remote_path,
|
|
|
- e,
|
|
|
- )
|
|
|
- await asyncio.sleep(2)
|
|
|
- else:
|
|
|
- logger.debug(
|
|
|
- "SD card cleanup failed after 3 attempts for %s: %s (non-critical)",
|
|
|
+ if subtask_name:
|
|
|
+ async with async_session() as db:
|
|
|
+ from backend.app.models.printer import Printer
|
|
|
+
|
|
|
+ result = await db.execute(select(Printer).where(Printer.id == printer_id))
|
|
|
+ printer = result.scalar_one_or_none()
|
|
|
+
|
|
|
+ if printer:
|
|
|
+ from backend.app.services.bambu_ftp import delete_file_async
|
|
|
+
|
|
|
+ # Try both .3mf and .gcode extensions — the printer may have either
|
|
|
+ for ext in (".3mf", ".gcode"):
|
|
|
+ remote_path = f"/{subtask_name}{ext}"
|
|
|
+ # Retry up to 3 times — the printer may still lock the filesystem briefly after a print ends
|
|
|
+ for attempt in range(1, 4):
|
|
|
+ try:
|
|
|
+ delete_result = await delete_file_async(
|
|
|
+ printer.ip_address,
|
|
|
+ printer.access_code,
|
|
|
remote_path,
|
|
|
- e,
|
|
|
+ printer_model=printer.model,
|
|
|
)
|
|
|
+ if delete_result:
|
|
|
+ logger.info("Deleted %s from printer %s SD card", remote_path, printer.name)
|
|
|
+ break # Success or file doesn't exist — no need to retry
|
|
|
+ except Exception as e:
|
|
|
+ if attempt < 3:
|
|
|
+ logger.debug(
|
|
|
+ "SD card cleanup attempt %d/3 failed for %s: %s, retrying in 2s",
|
|
|
+ attempt,
|
|
|
+ remote_path,
|
|
|
+ e,
|
|
|
+ )
|
|
|
+ await asyncio.sleep(2)
|
|
|
+ else:
|
|
|
+ logger.debug(
|
|
|
+ "SD card cleanup failed after 3 attempts for %s: %s (non-critical)",
|
|
|
+ remote_path,
|
|
|
+ e,
|
|
|
+ )
|
|
|
except Exception as e:
|
|
|
logger.debug("SD card file cleanup failed for printer %s: %s (non-critical)", printer_id, e)
|
|
|
|