mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-21 10:15:04 +02:00
fix(queue): create archive for library-file prints so 3MF usage tracking works (#364)
When a print was queued from the file manager (library_file_id path), the scheduler never created an archive or called register_expected_print(). This forced on_print_start to re-download the 3MF via FTP, and if that failed, a fallback archive with no file was created — breaking 3MF-based filament usage tracking entirely. The queue item's archive_id also stayed NULL, so the usage tracker couldn't find the AMS slot mapping. Now the scheduler creates an archive from the library file before uploading, sets item.archive_id, and the existing register_expected_print() call fires since archive is no longer None.
This commit is contained in:
@@ -903,12 +903,31 @@ class PrintScheduler:
|
||||
await self._power_off_if_needed(db, item)
|
||||
return
|
||||
# Library files store absolute paths
|
||||
from pathlib import Path
|
||||
|
||||
lib_path = Path(library_file.file_path)
|
||||
file_path = lib_path if lib_path.is_absolute() else settings.base_dir / library_file.file_path
|
||||
filename = library_file.filename
|
||||
|
||||
# Create archive from library file so usage tracking has access to the 3MF
|
||||
try:
|
||||
from backend.app.services.archive import ArchiveService
|
||||
|
||||
archive_service = ArchiveService(db)
|
||||
archive = await archive_service.archive_print(
|
||||
printer_id=item.printer_id,
|
||||
source_file=file_path,
|
||||
)
|
||||
if archive:
|
||||
item.archive_id = archive.id
|
||||
await db.flush()
|
||||
logger.info(
|
||||
"Queue item %s: Created archive %s from library file %s",
|
||||
item.id,
|
||||
archive.id,
|
||||
item.library_file_id,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning("Queue item %s: Failed to create archive from library file: %s", item.id, e)
|
||||
|
||||
else:
|
||||
# Neither archive nor library file specified
|
||||
item.status = "failed"
|
||||
|
||||
Reference in New Issue
Block a user