|
@@ -183,7 +183,7 @@ from backend.app.services.telegram_reactions import telegram_reaction_poller
|
|
|
from backend.app.services.wled import wled_manager
|
|
from backend.app.services.wled import wled_manager
|
|
|
from backend.app.utils.ams_drying import is_drying_active, temperature_alarm_suppressed
|
|
from backend.app.utils.ams_drying import is_drying_active, temperature_alarm_suppressed
|
|
|
from backend.app.utils.ams_humidity import ams_humidity_percent
|
|
from backend.app.utils.ams_humidity import ams_humidity_percent
|
|
|
-from backend.app.utils.filament_types import printer_filament_type
|
|
|
|
|
|
|
+from backend.app.utils.filament_types import printer_filament_type, support_filament_type
|
|
|
from backend.app.utils.fts_routing import extruder_for_inlet
|
|
from backend.app.utils.fts_routing import extruder_for_inlet
|
|
|
from backend.app.utils.local_time import to_naive_utc, utcnow_naive
|
|
from backend.app.utils.local_time import to_naive_utc, utcnow_naive
|
|
|
from backend.app.utils.print_jobs import is_internal_printer_job
|
|
from backend.app.utils.print_jobs import is_internal_printer_job
|
|
@@ -1693,6 +1693,23 @@ async def _fill_plate_estimates() -> None:
|
|
|
logging.getLogger(__name__).info("[ARCHIVE] Read the plate estimates of %d archive(s)", filled)
|
|
logging.getLogger(__name__).info("[ARCHIVE] Read the plate estimates of %d archive(s)", filled)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+_gcode_hashes_task: asyncio.Task | None = None
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def _fill_gcode_hashes() -> None:
|
|
|
|
|
+ from backend.app.services.archive_gcode_hash import fill_gcode_hashes
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ filled = await fill_gcode_hashes(async_session)
|
|
|
|
|
+ except asyncio.CancelledError:
|
|
|
|
|
+ raise
|
|
|
|
|
+ except Exception as exc:
|
|
|
|
|
+ logging.getLogger(__name__).warning("[ARCHIVE] Reading G-code fingerprints failed: %s", exc)
|
|
|
|
|
+ return
|
|
|
|
|
+ if filled:
|
|
|
|
|
+ logging.getLogger(__name__).info("[ARCHIVE] Read the G-code fingerprints of %d archive(s)", filled)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _partial_progress_scale(progress: int | float | None) -> float:
|
|
def _partial_progress_scale(progress: int | float | None) -> float:
|
|
|
"""Clamp ``progress / 100`` into [0.0, 1.0] for partial-print scaling.
|
|
"""Clamp ``progress / 100`` into [0.0, 1.0] for partial-print scaling.
|
|
|
|
|
|
|
@@ -2303,6 +2320,12 @@ async def on_printer_status_change(printer_id: int, state: PrinterState):
|
|
|
name=f"printer-offline-notify-{printer_id}",
|
|
name=f"printer-offline-notify-{printer_id}",
|
|
|
)
|
|
)
|
|
|
elif state.connected:
|
|
elif state.connected:
|
|
|
|
|
+ if prev_connected is False:
|
|
|
|
|
+ # A printer back from a dropped connection, often a restart, may
|
|
|
|
|
+ # take files again: don't hold it to an upload backoff from
|
|
|
|
|
+ # before (#3563). Not on Bambuddy's own start (no previous state).
|
|
|
|
|
+ client = printer_manager.get_client(printer_id)
|
|
|
|
|
+ print_scheduler.printer_reconnected(printer_id, client.ip_address if client else None)
|
|
|
# Kept until the relay can actually send online: with its broker down
|
|
# Kept until the relay can actually send online: with its broker down
|
|
|
# now, the next status update after the reconnect sends it.
|
|
# now, the next status update after the reconnect sends it.
|
|
|
if printer_id in _printer_offline_published and mqtt_relay.enabled and mqtt_relay.connected:
|
|
if printer_id in _printer_offline_published and mqtt_relay.enabled and mqtt_relay.connected:
|
|
@@ -2800,6 +2823,18 @@ def _slot_feeds_print(printer_id: int, ams_id: int, tray_id: int) -> bool:
|
|
|
return any(slot.has_filament and slot.holds(ams_id, tray_id) for slot in slots.values())
|
|
return any(slot.has_filament and slot.holds(ams_id, tray_id) for slot in slots.values())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _tray_reports_no_filament(color: str, tray_type: str) -> bool:
|
|
|
|
|
+ """Does this tray report carry no filament data at all?
|
|
|
|
|
+
|
|
|
|
|
+ No type, and a colour that is either empty or ``00000000``: firmware sends
|
|
|
|
|
+ both for a blank slot, and ``00000000`` is what Bambuddy's own slot reset
|
|
|
|
|
+ writes. A reconnect mid-print brought it in that form and got past every
|
|
|
|
|
+ guard that only knew the empty string (#3526). A clear spool also reports
|
|
|
|
|
+ ``00000000``, but always with a type, so it is not blank.
|
|
|
|
|
+ """
|
|
|
|
|
+ return not tray_type.strip() and color.strip().upper() in ("", "00000000")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_now: bool) -> None:
|
|
async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_now: bool) -> None:
|
|
|
"""Unlink built-in inventory assignments whose slot no longer holds their spool.
|
|
"""Unlink built-in inventory assignments whose slot no longer holds their spool.
|
|
|
|
|
|
|
@@ -2995,11 +3030,21 @@ async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_no
|
|
|
try:
|
|
try:
|
|
|
from backend.app.api.routes.inventory import (
|
|
from backend.app.api.routes.inventory import (
|
|
|
apply_spool_to_slot_via_mqtt,
|
|
apply_spool_to_slot_via_mqtt,
|
|
|
|
|
+ load_preset_lookup_user,
|
|
|
)
|
|
)
|
|
|
|
|
+ from backend.app.core.auth import is_auth_enabled
|
|
|
|
|
+
|
|
|
|
|
+ # Whoever made the assignment: their cloud sign-in
|
|
|
|
|
+ # resolves a custom preset, which nobody's did here,
|
|
|
|
|
+ # so the slot got Generic PLA on insert (#3519). With
|
|
|
|
|
+ # login off the shared sign-in applies, as before.
|
|
|
|
|
+ replay_user = None
|
|
|
|
|
+ if assignment.assigned_by_user_id is not None and await is_auth_enabled(db):
|
|
|
|
|
+ replay_user = await load_preset_lookup_user(db, assignment.assigned_by_user_id)
|
|
|
|
|
|
|
|
configured = await apply_spool_to_slot_via_mqtt(
|
|
configured = await apply_spool_to_slot_via_mqtt(
|
|
|
db=db,
|
|
db=db,
|
|
|
- current_user=None,
|
|
|
|
|
|
|
+ current_user=replay_user,
|
|
|
spool=assignment.spool,
|
|
spool=assignment.spool,
|
|
|
printer_id=printer_id,
|
|
printer_id=printer_id,
|
|
|
ams_id=assignment.ams_id,
|
|
ams_id=assignment.ams_id,
|
|
@@ -3044,7 +3089,7 @@ async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_no
|
|
|
# firmware clears colour and type when it unloads a spool
|
|
# firmware clears colour and type when it unloads a spool
|
|
|
# it just emptied. Unlinking here would erase the record
|
|
# it just emptied. Unlinking here would erase the record
|
|
|
# of which spool fed the print so far.
|
|
# of which spool fed the print so far.
|
|
|
- if printing_now and not cur_color.strip() and not cur_type.strip():
|
|
|
|
|
|
|
+ if printing_now and _tray_reports_no_filament(cur_color, cur_type):
|
|
|
logger.info(
|
|
logger.info(
|
|
|
"Auto-unlink skipped: spool %d AMS%d-T%d — tray data cleared during a running print "
|
|
"Auto-unlink skipped: spool %d AMS%d-T%d — tray data cleared during a running print "
|
|
|
"(runout?)",
|
|
"(runout?)",
|
|
@@ -3068,8 +3113,7 @@ async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_no
|
|
|
# rather than cancelling it (#3186).
|
|
# rather than cancelling it (#3186).
|
|
|
if (
|
|
if (
|
|
|
spool_present(current_tray) is True
|
|
spool_present(current_tray) is True
|
|
|
- and not cur_color.strip()
|
|
|
|
|
- and not cur_type.strip()
|
|
|
|
|
|
|
+ and _tray_reports_no_filament(cur_color, cur_type)
|
|
|
and not slot_unlink_grace.is_held(
|
|
and not slot_unlink_grace.is_held(
|
|
|
printer_id,
|
|
printer_id,
|
|
|
("inventory", assignment.ams_id, assignment.tray_id, assignment.spool_id),
|
|
("inventory", assignment.ams_id, assignment.tray_id, assignment.spool_id),
|
|
@@ -3088,7 +3132,7 @@ async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_no
|
|
|
# unit's bits, colour and type for a moment and lost
|
|
# unit's bits, colour and type for a moment and lost
|
|
|
# four saved assignments that way (#3186); unlink only
|
|
# four saved assignments that way (#3186); unlink only
|
|
|
# if the slot is still blank after the grace period.
|
|
# if the slot is still blank after the grace period.
|
|
|
- if not cur_color.strip() and not cur_type.strip():
|
|
|
|
|
|
|
+ if _tray_reports_no_filament(cur_color, cur_type):
|
|
|
hold_key = ("inventory", assignment.ams_id, assignment.tray_id, assignment.spool_id)
|
|
hold_key = ("inventory", assignment.ams_id, assignment.tray_id, assignment.spool_id)
|
|
|
if not slot_unlink_grace.removal_confirmed(printer_id, hold_key):
|
|
if not slot_unlink_grace.removal_confirmed(printer_id, hold_key):
|
|
|
held.add(hold_key)
|
|
held.add(hold_key)
|
|
@@ -3147,6 +3191,17 @@ async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_no
|
|
|
lp_type = await db.scalar(select(_LP.filament_type).where(_LP.id == int(lp_ref)))
|
|
lp_type = await db.scalar(select(_LP.filament_type).where(_LP.id == int(lp_ref)))
|
|
|
if lp_type:
|
|
if lp_type:
|
|
|
spool_types.add(printer_filament_type(lp_type).upper())
|
|
spool_types.add(printer_filament_type(lp_type).upper())
|
|
|
|
|
+ # A support spool went in with the slicer's suffix
|
|
|
|
|
+ # ("PLA-S") that none of the above carries (#3559).
|
|
|
|
|
+ # A spool made from a support RFID tray has its
|
|
|
|
|
+ # material as "Support For PLA", so that counts too.
|
|
|
|
|
+ support_name = (
|
|
|
|
|
+ f"{spool.slicer_filament_name or ''} {spool.material or ''} {spool.subtype or ''}"
|
|
|
|
|
+ )
|
|
|
|
|
+ spool_types |= {
|
|
|
|
|
+ support_filament_type(t, spool.slicer_filament, support_name).upper()
|
|
|
|
|
+ for t in spool_types
|
|
|
|
|
+ }
|
|
|
if (
|
|
if (
|
|
|
_colors_similar(cur_color, spool_color)
|
|
_colors_similar(cur_color, spool_color)
|
|
|
and printer_filament_type(cur_type).upper() in spool_types
|
|
and printer_filament_type(cur_type).upper() in spool_types
|
|
@@ -4979,6 +5034,277 @@ async def _dispatched_by_bambuddy(db, printer_id: int, filename: str | None, sub
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+async def _adopt_archive_for_run(
|
|
|
|
|
+ db: AsyncSession,
|
|
|
|
|
+ archive,
|
|
|
|
|
+ printer_id: int,
|
|
|
|
|
+ *,
|
|
|
|
|
+ starting_plate_id: int | None,
|
|
|
|
|
+ effective_subtask_id: str | None,
|
|
|
|
|
+ logger: logging.Logger,
|
|
|
|
|
+ started_at: datetime | None = None,
|
|
|
|
|
+) -> bool:
|
|
|
|
|
+ """Start a print's run on an archive that already exists: a reprint, a
|
|
|
|
|
+ queue print of a file printed before, or the same slice sent again from the
|
|
|
|
|
+ slicer (#1634). The archive says "printing" from now, without the previous
|
|
|
|
|
+ run's outcome, answer or timelapse, and on this printer with this print's
|
|
|
|
|
+ job id. False when the printer was deleted meanwhile: the adoption is
|
|
|
|
|
+ undone or was refused, the printer is forgotten, and the caller stops.
|
|
|
|
|
+ """
|
|
|
|
|
+ from backend.app.models.archive import PrintArchive
|
|
|
|
|
+
|
|
|
|
|
+ # As it was before this adoption: put back if the printer turns
|
|
|
|
|
+ # out to have been deleted while it was adopted (below).
|
|
|
|
|
+ before_adoption = {
|
|
|
|
|
+ attr.columns[0].name: getattr(archive, attr.key)
|
|
|
|
|
+ for attr in sa_inspect(PrintArchive).column_attrs
|
|
|
|
|
+ if attr.key != "id"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # Update archive status to printing
|
|
|
|
|
+ archive.status = "printing"
|
|
|
|
|
+ archive.started_at = started_at or datetime.now(timezone.utc)
|
|
|
|
|
+ # The previous run's outcome is not this one's: a reprint that
|
|
|
|
|
+ # completes must not keep showing why the last one failed.
|
|
|
|
|
+ archive.failure_reason = None
|
|
|
|
|
+ archive.completed_at = None
|
|
|
|
|
+
|
|
|
|
|
+ # The previous run's answer is still on this row and the
|
|
|
|
|
+ # completion prompt is gated on ``user_verdict is None`` (#1898),
|
|
|
|
|
+ # so without a reset the second run inherits the first run's
|
|
|
|
|
+ # verdict: no prompt at all, and a green "good" badge on a run
|
|
|
|
|
+ # nobody ever judged.
|
|
|
|
|
+ if archive.confirm_requested:
|
|
|
|
|
+ archive.user_verdict = None
|
|
|
|
|
+ archive.user_verdict_source = None
|
|
|
|
|
+ archive.user_verdict_at = None
|
|
|
|
|
+ archive.confirm_token = None
|
|
|
|
|
+ archive.confirm_token_used_at = None
|
|
|
|
|
+
|
|
|
|
|
+ # Reprint of an archive reuses the source row. Without resetting
|
|
|
|
|
+ # ``timelapse_path`` _scan_for_timelapse_with_retries early-returns
|
|
|
|
|
+ # ("already has timelapse") and _capture_finish_photo_from_timelapse
|
|
|
|
|
+ # extracts the *original* print's last frame, which then ships in
|
|
|
|
|
+ # the completion notification (#1707). Clear the path so the
|
|
|
|
|
+ # scanner runs fresh; also unlink the old video file so reprints
|
|
|
|
|
+ # don't accumulate orphans in the archive directory. Photos list
|
|
|
|
|
+ # is left alone — accumulating one finish photo per run is fine.
|
|
|
|
|
+ # The print-start baseline (#2704) is stale for the same reason:
|
|
|
|
|
+ # it describes the printer before the previous run. The capture
|
|
|
|
|
+ # below overwrites it, but clear it here too so an early failure
|
|
|
|
|
+ # can't leave the scan diffing against the wrong snapshot.
|
|
|
|
|
+ #
|
|
|
|
|
+ # Unlinked only when it is the same plate printing again. Every
|
|
|
|
|
+ # plate of a Send All shares this archive, and the video on it
|
|
|
|
|
+ # can be the only copy of another plate's run -- the printer's
|
|
|
|
|
+ # was deleted once it attached (#3275). That one is left in the
|
|
|
|
|
+ # archive directory, which goes with the archive. A video whose
|
|
|
|
|
+ # plate is not on record (attached by hand, or before the
|
|
|
|
|
+ # column existed) is kept too where the 3MF has other plates,
|
|
|
|
|
+ # or cannot be read: nothing tells it apart from another plate's,
|
|
|
|
|
+ # and keeping costs one file where deleting can cost the only
|
|
|
|
|
+ # copy. On an archive with exactly one plate it is that plate's.
|
|
|
|
|
+ archive.timelapse_baseline = None
|
|
|
|
|
+ stale_timelapse_relpath = archive.timelapse_path
|
|
|
|
|
+ stale_timelapse_plate_id = archive.timelapse_plate_id
|
|
|
|
|
+ if stale_timelapse_relpath:
|
|
|
|
|
+ archive.timelapse_path = None
|
|
|
|
|
+ archive.timelapse_plate_id = None
|
|
|
|
|
+ stale_is_this_plates = stale_timelapse_plate_id == starting_plate_id
|
|
|
|
|
+ if stale_timelapse_relpath and stale_timelapse_plate_id is None and archive.file_path:
|
|
|
|
|
+ from backend.app.services.archive import plate_indexes_in_3mf
|
|
|
|
|
+
|
|
|
|
|
+ plates = await asyncio.to_thread(
|
|
|
|
|
+ plate_indexes_in_3mf,
|
|
|
|
|
+ app_settings.base_dir / archive.file_path, # SEC-PATH-OK: stored relative archive path
|
|
|
|
|
+ )
|
|
|
|
|
+ stale_is_this_plates = len(plates) == 1
|
|
|
|
|
+ if stale_timelapse_relpath and not stale_is_this_plates:
|
|
|
|
|
+ logger.info(
|
|
|
|
|
+ "Kept timelapse %s of plate %s on archive %s: plate %s is starting",
|
|
|
|
|
+ stale_timelapse_relpath,
|
|
|
|
|
+ stale_timelapse_plate_id,
|
|
|
|
|
+ archive.id,
|
|
|
|
|
+ starting_plate_id,
|
|
|
|
|
+ )
|
|
|
|
|
+ # The video is deleted once the adoption stands (below).
|
|
|
|
|
+ delete_stale_video = bool(stale_timelapse_relpath) and stale_is_this_plates
|
|
|
|
|
+ # Update on first-set OR on reprint (the queue dispatcher mints
|
|
|
|
|
+ # a fresh subtask_id per dispatch in bambu_mqtt:3647). Skipping
|
|
|
|
|
+ # the rewrite for reprints leaves the archive holding the FIRST
|
|
|
|
|
+ # run's id; if MQTT then reconnects mid-print, the reconciler
|
|
|
|
|
+ # (#1542) compares the stale stored id against the printer's
|
|
|
|
|
+ # live id, sees a mismatch, and synthesises a bogus PRINT
|
|
|
|
|
+ # COMPLETE — exactly the false-positive "Print Stopped" reported
|
|
|
|
|
+ # in #1807. Inequality check preserves the noop-on-stable-push
|
|
|
|
|
+ # behaviour the earlier `not archive.subtask_id` guard provided.
|
|
|
|
|
+ if effective_subtask_id and archive.subtask_id != effective_subtask_id:
|
|
|
|
|
+ archive.subtask_id = effective_subtask_id
|
|
|
|
|
+ # #1403 follow-up: VP-queue archives are created with
|
|
|
|
|
+ # printer_id=None at queue-add time (we don't know which
|
|
|
|
|
+ # printer will run the job yet). When the print actually
|
|
|
|
|
+ # starts on a specific printer the expected-archive lookup
|
|
|
|
|
+ # used to skip this assignment, leaving printer_id=None
|
|
|
|
|
+ # forever — which then disables the "Scan for timelapse"
|
|
|
|
|
+ # button in ArchivesPage (gated on !archive.printer_id).
|
|
|
|
|
+ if archive.printer_id != printer_id:
|
|
|
|
|
+ archive.printer_id = printer_id
|
|
|
|
|
+ adopting_id = archive.id # a rollback expires the object
|
|
|
|
|
+ try:
|
|
|
|
|
+ await db.commit()
|
|
|
|
|
+ except (IntegrityError, StaleDataError):
|
|
|
|
|
+ # The archive stays unchanged, or is gone: "delete archives"
|
|
|
|
|
+ # removed the row under the adoption, which then matched no
|
|
|
|
|
+ # row (StaleDataError) rather than being refused.
|
|
|
|
|
+ if await _refused_for_deleted_printer(db, printer_id, f"archive {adopting_id} was adopted"):
|
|
|
|
|
+ return False
|
|
|
|
|
+ raise
|
|
|
|
|
+
|
|
|
|
|
+ # The printer can be deleted between the check above and this
|
|
|
|
|
+ # commit (the route's transaction lasts seconds), and the commit
|
|
|
|
|
+ # then adopted the archive anyway: status, verdict and timelapse
|
|
|
|
|
+ # changed, and the deleted printer's id written on a row the
|
|
|
|
|
+ # route had detached or never touched. Undo the adoption.
|
|
|
|
|
+ if await _printer_gone(db, printer_id):
|
|
|
|
|
+ logger.info(
|
|
|
|
|
+ "Printer %s was deleted while archive %s was adopted; undoing the adoption",
|
|
|
|
|
+ printer_id,
|
|
|
|
|
+ archive.id,
|
|
|
|
|
+ )
|
|
|
|
|
+ # Everything as before this adoption. The printer it had
|
|
|
|
|
+ # then stays, unless it was the deleted one: the route
|
|
|
|
|
+ # detached that row (kept) or deleted it (no row matches).
|
|
|
|
|
+ previous_printer = before_adoption["printer_id"]
|
|
|
|
|
+ await db.execute(
|
|
|
|
|
+ update(PrintArchive)
|
|
|
|
|
+ .where(PrintArchive.id == archive.id)
|
|
|
|
|
+ .values(
|
|
|
|
|
+ {
|
|
|
|
|
+ **before_adoption,
|
|
|
|
|
+ "printer_id": None if previous_printer == printer_id else previous_printer,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ await db.commit()
|
|
|
|
|
+ await forget_printer(printer_id)
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+ await _drop_replaced_plate_videos(
|
|
|
|
|
+ db,
|
|
|
|
|
+ archive.id,
|
|
|
|
|
+ starting_plate_id,
|
|
|
|
|
+ stale_timelapse_relpath if delete_stale_video else None,
|
|
|
|
|
+ logger,
|
|
|
|
|
+ )
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def _claim_slicer_resend_archive(db: AsyncSession, printer_id: int, source: Path):
|
|
|
|
|
+ """The archive a print sent from the slicer adds its run to, or None for a
|
|
|
|
|
+ new one (#1634): the same G-code, so the same slice sent again in a new 3MF.
|
|
|
|
|
+
|
|
|
|
|
+ As a queue print of a file printed before (``_claim_reusable_archive`` in
|
|
|
|
|
+ the scheduler): the same owner (who started the print, nobody for a print
|
|
|
|
|
+ from the slicer) and no project, and no File Manager file, whose own prints
|
|
|
|
|
+ find its archive by the file's bytes. Not one a merge is moving. Held in
|
|
|
|
|
+ ``archive_work`` from here, with no await between, until the caller
|
|
|
|
|
+ releases it once the run is open.
|
|
|
|
|
+
|
|
|
|
|
+ Returns the archive and whether something else holds it already: a queue
|
|
|
|
|
+ dispatch uploading or printing its file, which the file must stay for.
|
|
|
|
|
+ """
|
|
|
|
|
+ from backend.app.models.archive import PrintArchive
|
|
|
|
|
+ from backend.app.services import archive_work
|
|
|
|
|
+ from backend.app.services.archive_gcode_hash import gcode_fingerprint
|
|
|
|
|
+
|
|
|
|
|
+ # Unzipping a large 3MF takes seconds: off the event loop.
|
|
|
|
|
+ fingerprint = await asyncio.to_thread(gcode_fingerprint, source)
|
|
|
|
|
+ if not fingerprint:
|
|
|
|
|
+ return None
|
|
|
|
|
+ owner_id = await _print_user_id_if_still_there(db, printer_manager.get_current_print_user(printer_id))
|
|
|
|
|
+ owner = PrintArchive.created_by_id.is_(None) if owner_id is None else PrintArchive.created_by_id == owner_id
|
|
|
|
|
+ candidates = (
|
|
|
|
|
+ await db.scalars(
|
|
|
|
|
+ select(PrintArchive)
|
|
|
|
|
+ .where(
|
|
|
|
|
+ PrintArchive.gcode_hash == fingerprint,
|
|
|
|
|
+ owner,
|
|
|
|
|
+ PrintArchive.project_id.is_(None),
|
|
|
|
|
+ PrintArchive.library_file_id.is_(None),
|
|
|
|
|
+ PrintArchive.deleted_at.is_(None),
|
|
|
|
|
+ )
|
|
|
|
|
+ .order_by(PrintArchive.id.desc())
|
|
|
|
|
+ )
|
|
|
|
|
+ ).all()
|
|
|
|
|
+ for candidate in candidates:
|
|
|
|
|
+ if archive_work.is_merging(candidate.id):
|
|
|
|
|
+ continue
|
|
|
|
|
+ in_use = archive_work.is_held(candidate.id)
|
|
|
|
|
+ archive_work.hold(candidate.id)
|
|
|
|
|
+ return candidate, in_use
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def _start_slicer_resend_run(
|
|
|
|
|
+ db: AsyncSession,
|
|
|
|
|
+ archive,
|
|
|
|
|
+ printer_id: int,
|
|
|
|
|
+ *,
|
|
|
|
|
+ source: Path,
|
|
|
|
|
+ print_data: dict,
|
|
|
|
|
+ subtask_id: str | None,
|
|
|
|
|
+ started_at: datetime | None,
|
|
|
|
|
+ original_filename: str | None,
|
|
|
|
|
+ logger: logging.Logger,
|
|
|
|
|
+ file_in_use: bool = False,
|
|
|
|
|
+):
|
|
|
|
|
+ """Start this print's run on the archive ``_claim_slicer_resend_archive``
|
|
|
|
|
+ found (#1634). The archive takes the new file in place of its own, unless
|
|
|
|
|
+ another print of it is running, or a queue dispatch holds it
|
|
|
|
|
+ (``file_in_use``): that one still reads the file (its upload, pauses,
|
|
|
|
|
+ objects and estimate), and the G-code is the same. None when the printer
|
|
|
|
|
+ was deleted meanwhile; the caller stops.
|
|
|
|
|
+ """
|
|
|
|
|
+ from backend.app.models.print_log import INCLUDE_OPEN_RUNS, RUN_OPEN, PrintLogEntry
|
|
|
|
|
+
|
|
|
|
|
+ printing_elsewhere = file_in_use or (
|
|
|
|
|
+ await db.scalar(
|
|
|
|
|
+ select(PrintLogEntry.id)
|
|
|
|
|
+ .where(PrintLogEntry.archive_id == archive.id, PrintLogEntry.status == RUN_OPEN)
|
|
|
|
|
+ .limit(1)
|
|
|
|
|
+ .execution_options(**{INCLUDE_OPEN_RUNS: True})
|
|
|
|
|
+ )
|
|
|
|
|
+ is not None
|
|
|
|
|
+ )
|
|
|
|
|
+ if not printing_elsewhere:
|
|
|
|
|
+ replaced = await ArchiveService(db).archive_print(
|
|
|
|
|
+ printer_id=printer_id,
|
|
|
|
|
+ source_file=source,
|
|
|
|
|
+ print_data=print_data,
|
|
|
|
|
+ subtask_id=subtask_id,
|
|
|
|
|
+ original_filename=original_filename,
|
|
|
|
|
+ replace_archive_id=archive.id,
|
|
|
|
|
+ )
|
|
|
|
|
+ if replaced is not None:
|
|
|
|
|
+ archive = replaced
|
|
|
|
|
+ else:
|
|
|
|
|
+ # The copy failed its check, or the printer is gone (the adoption
|
|
|
|
|
+ # below says so): the run still joins, on the file it has.
|
|
|
|
|
+ logger.warning("Archive %s keeps its file: the one sent again could not be taken", archive.id)
|
|
|
|
|
+ client = printer_manager.get_client(printer_id)
|
|
|
|
|
+ if not await _adopt_archive_for_run(
|
|
|
|
|
+ db,
|
|
|
|
|
+ archive,
|
|
|
|
|
+ printer_id,
|
|
|
|
|
+ starting_plate_id=resolve_plate_id(client.state) if client else None,
|
|
|
|
|
+ effective_subtask_id=subtask_id,
|
|
|
|
|
+ logger=logger,
|
|
|
|
|
+ started_at=started_at,
|
|
|
|
|
+ ):
|
|
|
|
|
+ return None
|
|
|
|
|
+ return archive
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async def on_print_start(printer_id: int, data: dict):
|
|
async def on_print_start(printer_id: int, data: dict):
|
|
|
"""Handle print start - archive the 3MF file immediately."""
|
|
"""Handle print start - archive the 3MF file immediately."""
|
|
|
logger = logging.getLogger(__name__)
|
|
logger = logging.getLogger(__name__)
|
|
@@ -5374,83 +5700,6 @@ async def on_print_start(printer_id: int, data: dict):
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
if archive:
|
|
if archive:
|
|
|
- # As it was before this adoption: put back if the printer turns
|
|
|
|
|
- # out to have been deleted while it was adopted (below).
|
|
|
|
|
- before_adoption = {
|
|
|
|
|
- attr.columns[0].name: getattr(archive, attr.key)
|
|
|
|
|
- for attr in sa_inspect(PrintArchive).column_attrs
|
|
|
|
|
- if attr.key != "id"
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- # Update archive status to printing
|
|
|
|
|
- archive.status = "printing"
|
|
|
|
|
- archive.started_at = datetime.now(timezone.utc)
|
|
|
|
|
- # The previous run's outcome is not this one's: a reprint that
|
|
|
|
|
- # completes must not keep showing why the last one failed.
|
|
|
|
|
- archive.failure_reason = None
|
|
|
|
|
- archive.completed_at = None
|
|
|
|
|
-
|
|
|
|
|
- # The previous run's answer is still on this row and the
|
|
|
|
|
- # completion prompt is gated on ``user_verdict is None`` (#1898),
|
|
|
|
|
- # so without a reset the second run inherits the first run's
|
|
|
|
|
- # verdict: no prompt at all, and a green "good" badge on a run
|
|
|
|
|
- # nobody ever judged.
|
|
|
|
|
- if archive.confirm_requested:
|
|
|
|
|
- archive.user_verdict = None
|
|
|
|
|
- archive.user_verdict_source = None
|
|
|
|
|
- archive.user_verdict_at = None
|
|
|
|
|
- archive.confirm_token = None
|
|
|
|
|
- archive.confirm_token_used_at = None
|
|
|
|
|
-
|
|
|
|
|
- # Reprint of an archive reuses the source row. Without resetting
|
|
|
|
|
- # ``timelapse_path`` _scan_for_timelapse_with_retries early-returns
|
|
|
|
|
- # ("already has timelapse") and _capture_finish_photo_from_timelapse
|
|
|
|
|
- # extracts the *original* print's last frame, which then ships in
|
|
|
|
|
- # the completion notification (#1707). Clear the path so the
|
|
|
|
|
- # scanner runs fresh; also unlink the old video file so reprints
|
|
|
|
|
- # don't accumulate orphans in the archive directory. Photos list
|
|
|
|
|
- # is left alone — accumulating one finish photo per run is fine.
|
|
|
|
|
- # The print-start baseline (#2704) is stale for the same reason:
|
|
|
|
|
- # it describes the printer before the previous run. The capture
|
|
|
|
|
- # below overwrites it, but clear it here too so an early failure
|
|
|
|
|
- # can't leave the scan diffing against the wrong snapshot.
|
|
|
|
|
- #
|
|
|
|
|
- # Unlinked only when it is the same plate printing again. Every
|
|
|
|
|
- # plate of a Send All shares this archive, and the video on it
|
|
|
|
|
- # can be the only copy of another plate's run -- the printer's
|
|
|
|
|
- # was deleted once it attached (#3275). That one is left in the
|
|
|
|
|
- # archive directory, which goes with the archive. A video whose
|
|
|
|
|
- # plate is not on record (attached by hand, or before the
|
|
|
|
|
- # column existed) is kept too where the 3MF has other plates,
|
|
|
|
|
- # or cannot be read: nothing tells it apart from another plate's,
|
|
|
|
|
- # and keeping costs one file where deleting can cost the only
|
|
|
|
|
- # copy. On an archive with exactly one plate it is that plate's.
|
|
|
|
|
- archive.timelapse_baseline = None
|
|
|
|
|
- stale_timelapse_relpath = archive.timelapse_path
|
|
|
|
|
- stale_timelapse_plate_id = archive.timelapse_plate_id
|
|
|
|
|
- starting_plate_id = _print_plate_ids.get((printer_id, expected_archive_id))
|
|
|
|
|
- if stale_timelapse_relpath:
|
|
|
|
|
- archive.timelapse_path = None
|
|
|
|
|
- archive.timelapse_plate_id = None
|
|
|
|
|
- stale_is_this_plates = stale_timelapse_plate_id == starting_plate_id
|
|
|
|
|
- if stale_timelapse_relpath and stale_timelapse_plate_id is None and archive.file_path:
|
|
|
|
|
- from backend.app.services.archive import plate_indexes_in_3mf
|
|
|
|
|
-
|
|
|
|
|
- plates = await asyncio.to_thread(
|
|
|
|
|
- plate_indexes_in_3mf,
|
|
|
|
|
- app_settings.base_dir / archive.file_path, # SEC-PATH-OK: stored relative archive path
|
|
|
|
|
- )
|
|
|
|
|
- stale_is_this_plates = len(plates) == 1
|
|
|
|
|
- if stale_timelapse_relpath and not stale_is_this_plates:
|
|
|
|
|
- logger.info(
|
|
|
|
|
- "Kept timelapse %s of plate %s on archive %s: plate %s is starting",
|
|
|
|
|
- stale_timelapse_relpath,
|
|
|
|
|
- stale_timelapse_plate_id,
|
|
|
|
|
- expected_archive_id,
|
|
|
|
|
- starting_plate_id,
|
|
|
|
|
- )
|
|
|
|
|
- # The video is deleted once the adoption stands (below).
|
|
|
|
|
- delete_stale_video = bool(stale_timelapse_relpath) and stale_is_this_plates
|
|
|
|
|
# Persist a restart-stable id so a later restart resumes this
|
|
# Persist a restart-stable id so a later restart resumes this
|
|
|
# archive by subtask_id instead of name-matching + duplicating
|
|
# archive by subtask_id instead of name-matching + duplicating
|
|
|
# it (#1485). The printer often hasn't echoed subtask_id back
|
|
# it (#1485). The printer often hasn't echoed subtask_id back
|
|
@@ -5466,73 +5715,16 @@ async def on_print_start(printer_id: int, data: dict):
|
|
|
_dispatched = getattr(_client, "last_dispatch_subtask_id", None) if _client else None
|
|
_dispatched = getattr(_client, "last_dispatch_subtask_id", None) if _client else None
|
|
|
if _dispatched:
|
|
if _dispatched:
|
|
|
effective_subtask_id = str(_dispatched).strip() or None
|
|
effective_subtask_id = str(_dispatched).strip() or None
|
|
|
- # Update on first-set OR on reprint (the queue dispatcher mints
|
|
|
|
|
- # a fresh subtask_id per dispatch in bambu_mqtt:3647). Skipping
|
|
|
|
|
- # the rewrite for reprints leaves the archive holding the FIRST
|
|
|
|
|
- # run's id; if MQTT then reconnects mid-print, the reconciler
|
|
|
|
|
- # (#1542) compares the stale stored id against the printer's
|
|
|
|
|
- # live id, sees a mismatch, and synthesises a bogus PRINT
|
|
|
|
|
- # COMPLETE — exactly the false-positive "Print Stopped" reported
|
|
|
|
|
- # in #1807. Inequality check preserves the noop-on-stable-push
|
|
|
|
|
- # behaviour the earlier `not archive.subtask_id` guard provided.
|
|
|
|
|
- if effective_subtask_id and archive.subtask_id != effective_subtask_id:
|
|
|
|
|
- archive.subtask_id = effective_subtask_id
|
|
|
|
|
- # #1403 follow-up: VP-queue archives are created with
|
|
|
|
|
- # printer_id=None at queue-add time (we don't know which
|
|
|
|
|
- # printer will run the job yet). When the print actually
|
|
|
|
|
- # starts on a specific printer the expected-archive lookup
|
|
|
|
|
- # used to skip this assignment, leaving printer_id=None
|
|
|
|
|
- # forever — which then disables the "Scan for timelapse"
|
|
|
|
|
- # button in ArchivesPage (gated on !archive.printer_id).
|
|
|
|
|
- if archive.printer_id != printer_id:
|
|
|
|
|
- archive.printer_id = printer_id
|
|
|
|
|
- adopting_id = archive.id # a rollback expires the object
|
|
|
|
|
- try:
|
|
|
|
|
- await db.commit()
|
|
|
|
|
- except (IntegrityError, StaleDataError):
|
|
|
|
|
- # The archive stays unchanged, or is gone: "delete archives"
|
|
|
|
|
- # removed the row under the adoption, which then matched no
|
|
|
|
|
- # row (StaleDataError) rather than being refused.
|
|
|
|
|
- if await _refused_for_deleted_printer(db, printer_id, f"archive {adopting_id} was adopted"):
|
|
|
|
|
- return
|
|
|
|
|
- raise
|
|
|
|
|
-
|
|
|
|
|
- # The printer can be deleted between the check above and this
|
|
|
|
|
- # commit (the route's transaction lasts seconds), and the commit
|
|
|
|
|
- # then adopted the archive anyway: status, verdict and timelapse
|
|
|
|
|
- # changed, and the deleted printer's id written on a row the
|
|
|
|
|
- # route had detached or never touched. Undo the adoption.
|
|
|
|
|
- if await _printer_gone(db, printer_id):
|
|
|
|
|
- logger.info(
|
|
|
|
|
- "Printer %s was deleted while archive %s was adopted; undoing the adoption",
|
|
|
|
|
- printer_id,
|
|
|
|
|
- archive.id,
|
|
|
|
|
- )
|
|
|
|
|
- # Everything as before this adoption. The printer it had
|
|
|
|
|
- # then stays, unless it was the deleted one: the route
|
|
|
|
|
- # detached that row (kept) or deleted it (no row matches).
|
|
|
|
|
- previous_printer = before_adoption["printer_id"]
|
|
|
|
|
- await db.execute(
|
|
|
|
|
- update(PrintArchive)
|
|
|
|
|
- .where(PrintArchive.id == archive.id)
|
|
|
|
|
- .values(
|
|
|
|
|
- {
|
|
|
|
|
- **before_adoption,
|
|
|
|
|
- "printer_id": None if previous_printer == printer_id else previous_printer,
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- await db.commit()
|
|
|
|
|
- await forget_printer(printer_id)
|
|
|
|
|
- return
|
|
|
|
|
-
|
|
|
|
|
- await _drop_replaced_plate_videos(
|
|
|
|
|
|
|
+ starting_plate_id = _print_plate_ids.get((printer_id, expected_archive_id))
|
|
|
|
|
+ if not await _adopt_archive_for_run(
|
|
|
db,
|
|
db,
|
|
|
- archive.id,
|
|
|
|
|
- starting_plate_id,
|
|
|
|
|
- stale_timelapse_relpath if delete_stale_video else None,
|
|
|
|
|
- logger,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ archive,
|
|
|
|
|
+ printer_id,
|
|
|
|
|
+ starting_plate_id=starting_plate_id,
|
|
|
|
|
+ effective_subtask_id=effective_subtask_id,
|
|
|
|
|
+ logger=logger,
|
|
|
|
|
+ ):
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
# Track as active print
|
|
# Track as active print
|
|
|
_bind_active_print(printer_id, archive.id, archive.filename, filename, subtask_name)
|
|
_bind_active_print(printer_id, archive.id, archive.filename, filename, subtask_name)
|
|
@@ -6567,26 +6759,50 @@ async def on_print_start(printer_id: int, data: dict):
|
|
|
await _send_print_start_notification(printer_id, data, logger=logger)
|
|
await _send_print_start_notification(printer_id, data, logger=logger)
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
|
|
+ # The archive of the same slice sent before, which this print adds a
|
|
|
|
|
+ # run to instead of a new archive (#1634). Held until its run is open.
|
|
|
|
|
+ joined_archive_id: int | None = None
|
|
|
try:
|
|
try:
|
|
|
# Archive the file with status "printing"
|
|
# Archive the file with status "printing"
|
|
|
service = ArchiveService(db)
|
|
service = ArchiveService(db)
|
|
|
|
|
+ start_print_data = {
|
|
|
|
|
+ **data,
|
|
|
|
|
+ "status": "printing",
|
|
|
|
|
+ # Where the 3MF came from when the printer had none to
|
|
|
|
|
+ # give (#3307), for whoever reads this archive later.
|
|
|
|
|
+ **({"_3mf_from_archive": reused_3mf_from} if reused_3mf_from is not None else {}),
|
|
|
|
|
+ }
|
|
|
|
|
+ # The reused copy's temp name carries the printer id; a
|
|
|
|
|
+ # download's is the file's own name, as before.
|
|
|
|
|
+ start_filename = downloaded_filename if reused_3mf_from is not None else None
|
|
|
try:
|
|
try:
|
|
|
- archive = await service.archive_print(
|
|
|
|
|
- printer_id=printer_id,
|
|
|
|
|
- source_file=temp_path,
|
|
|
|
|
- print_data={
|
|
|
|
|
- **data,
|
|
|
|
|
- "status": "printing",
|
|
|
|
|
- # Where the 3MF came from when the printer had none to
|
|
|
|
|
- # give (#3307), for whoever reads this archive later.
|
|
|
|
|
- **({"_3mf_from_archive": reused_3mf_from} if reused_3mf_from is not None else {}),
|
|
|
|
|
- },
|
|
|
|
|
- subtask_id=subtask_id,
|
|
|
|
|
- started_at=detected_at,
|
|
|
|
|
- # The reused copy's temp name carries the printer id; a
|
|
|
|
|
- # download's is the file's own name, as before.
|
|
|
|
|
- original_filename=downloaded_filename if reused_3mf_from is not None else None,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ claimed = await _claim_slicer_resend_archive(db, printer_id, temp_path)
|
|
|
|
|
+ if claimed is not None:
|
|
|
|
|
+ joined, file_in_use = claimed
|
|
|
|
|
+ joined_archive_id = joined.id
|
|
|
|
|
+ archive = await _start_slicer_resend_run(
|
|
|
|
|
+ db,
|
|
|
|
|
+ joined,
|
|
|
|
|
+ printer_id,
|
|
|
|
|
+ source=temp_path,
|
|
|
|
|
+ print_data=start_print_data,
|
|
|
|
|
+ subtask_id=subtask_id,
|
|
|
|
|
+ started_at=detected_at,
|
|
|
|
|
+ original_filename=start_filename,
|
|
|
|
|
+ logger=logger,
|
|
|
|
|
+ file_in_use=file_in_use,
|
|
|
|
|
+ )
|
|
|
|
|
+ if archive is None:
|
|
|
|
|
+ return
|
|
|
|
|
+ else:
|
|
|
|
|
+ archive = await service.archive_print(
|
|
|
|
|
+ printer_id=printer_id,
|
|
|
|
|
+ source_file=temp_path,
|
|
|
|
|
+ print_data=start_print_data,
|
|
|
|
|
+ subtask_id=subtask_id,
|
|
|
|
|
+ started_at=detected_at,
|
|
|
|
|
+ original_filename=start_filename,
|
|
|
|
|
+ )
|
|
|
except IntegrityError:
|
|
except IntegrityError:
|
|
|
# archive_print removed the folder it had copied the 3MF into.
|
|
# archive_print removed the folder it had copied the 3MF into.
|
|
|
if await _refused_for_deleted_printer(db, printer_id, "its archive was written"):
|
|
if await _refused_for_deleted_printer(db, printer_id, "its archive was written"):
|
|
@@ -6622,41 +6838,55 @@ async def on_print_start(printer_id: int, data: dict):
|
|
|
logger.warning(
|
|
logger.warning(
|
|
|
"Could not reload archive %s after the failed flag write: %s", archive_id, reload_error
|
|
"Could not reload archive %s after the failed flag write: %s", archive_id, reload_error
|
|
|
)
|
|
)
|
|
|
|
|
+ if archive is None:
|
|
|
|
|
+ # Deleted meanwhile: nothing to register the print for.
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
- if await _drop_archive_of_deleted_printer(db, printer_id, archive_id):
|
|
|
|
|
|
|
+ # Not a joined archive: it is not this print's to remove, and
|
|
|
|
|
+ # its adoption already checked the printer.
|
|
|
|
|
+ if joined_archive_id is None and await _drop_archive_of_deleted_printer(db, printer_id, archive_id):
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
# Track this active print (use both original filename and downloaded filename)
|
|
# Track this active print (use both original filename and downloaded filename)
|
|
|
_bind_active_print(printer_id, archive_id, downloaded_filename, filename, subtask_name)
|
|
_bind_active_print(printer_id, archive_id, downloaded_filename, filename, subtask_name)
|
|
|
await _open_run_for(archive_id, printer_id, subtask_id)
|
|
await _open_run_for(archive_id, printer_id, subtask_id)
|
|
|
|
|
|
|
|
- logger.info("Created archive %s for %s", archive.id, downloaded_filename)
|
|
|
|
|
|
|
+ if joined_archive_id is not None:
|
|
|
|
|
+ logger.info(
|
|
|
|
|
+ "Added the print of %s to archive %s: the same G-code was sent again",
|
|
|
|
|
+ downloaded_filename,
|
|
|
|
|
+ archive_id,
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ logger.info("Created archive %s for %s", archive.id, downloaded_filename)
|
|
|
|
|
|
|
|
_maybe_start_layer_timelapse(printer, printer_id, archive.id)
|
|
_maybe_start_layer_timelapse(printer, printer_id, archive.id)
|
|
|
|
|
|
|
|
# Record starting energy from smart plug if available (#941: persisted column)
|
|
# Record starting energy from smart plug if available (#941: persisted column)
|
|
|
await _record_energy_start(archive, printer_id, db, context="auto-archive")
|
|
await _record_energy_start(archive, printer_id, db, context="auto-archive")
|
|
|
|
|
|
|
|
- await ws_manager.send_archive_created(
|
|
|
|
|
- {
|
|
|
|
|
- "id": archive.id,
|
|
|
|
|
- "printer_id": archive.printer_id,
|
|
|
|
|
- "filename": archive.filename,
|
|
|
|
|
- "print_name": archive.print_name,
|
|
|
|
|
- "status": archive.status,
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ archive_event = {
|
|
|
|
|
+ "id": archive.id,
|
|
|
|
|
+ "printer_id": archive.printer_id,
|
|
|
|
|
+ "filename": archive.filename,
|
|
|
|
|
+ "print_name": archive.print_name,
|
|
|
|
|
+ "status": archive.status,
|
|
|
|
|
+ }
|
|
|
|
|
+ if joined_archive_id is not None:
|
|
|
|
|
+ await ws_manager.send_archive_updated(archive_event)
|
|
|
|
|
+ else:
|
|
|
|
|
+ await ws_manager.send_archive_created(archive_event)
|
|
|
|
|
|
|
|
- # MQTT relay - publish archive created
|
|
|
|
|
- try:
|
|
|
|
|
- await mqtt_relay.on_archive_created(
|
|
|
|
|
- archive_id=archive.id,
|
|
|
|
|
- print_name=archive.print_name,
|
|
|
|
|
- printer_name=printer.name,
|
|
|
|
|
- status=archive.status,
|
|
|
|
|
- )
|
|
|
|
|
- except Exception:
|
|
|
|
|
- pass # Don't fail if MQTT fails
|
|
|
|
|
|
|
+ # MQTT relay - publish archive created
|
|
|
|
|
+ try:
|
|
|
|
|
+ await mqtt_relay.on_archive_created(
|
|
|
|
|
+ archive_id=archive.id,
|
|
|
|
|
+ print_name=archive.print_name or "",
|
|
|
|
|
+ printer_name=printer.name if printer else "",
|
|
|
|
|
+ status=archive.status,
|
|
|
|
|
+ )
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass # Don't fail if MQTT fails
|
|
|
|
|
|
|
|
# Send notification with archive data (new archive created)
|
|
# Send notification with archive data (new archive created)
|
|
|
if not notification_sent:
|
|
if not notification_sent:
|
|
@@ -6726,6 +6956,10 @@ async def on_print_start(printer_id: int, data: dict):
|
|
|
await _capture_timelapse_baseline_at_start(printer, printer_id, logger, archive_id=archive.id)
|
|
await _capture_timelapse_baseline_at_start(printer, printer_id, logger, archive_id=archive.id)
|
|
|
await _forget_if_printer_gone(printer_id)
|
|
await _forget_if_printer_gone(printer_id)
|
|
|
finally:
|
|
finally:
|
|
|
|
|
+ if joined_archive_id is not None:
|
|
|
|
|
+ from backend.app.services import archive_work
|
|
|
|
|
+
|
|
|
|
|
+ archive_work.release(joined_archive_id)
|
|
|
# Keep temp_path around until print completes so the cover endpoint
|
|
# Keep temp_path around until print completes so the cover endpoint
|
|
|
# can reuse it (#972). Cache eviction in on_print_complete deletes
|
|
# can reuse it (#972). Cache eviction in on_print_complete deletes
|
|
|
# the file. If the cache entry was evicted early (file vanished),
|
|
# the file. If the cache entry was evicted early (file vanished),
|
|
@@ -12080,6 +12314,12 @@ async def lifespan(app: FastAPI):
|
|
|
global _plate_estimates_task
|
|
global _plate_estimates_task
|
|
|
_plate_estimates_task = asyncio.create_task(_fill_plate_estimates())
|
|
_plate_estimates_task = asyncio.create_task(_fill_plate_estimates())
|
|
|
|
|
|
|
|
|
|
+ # The G-code fingerprint of archives made before it was kept (#1634), read
|
|
|
|
|
+ # from their files in the background: until then a slice sent again from
|
|
|
|
|
+ # the slicer archives anew, as before.
|
|
|
|
|
+ global _gcode_hashes_task
|
|
|
|
|
+ _gcode_hashes_task = asyncio.create_task(_fill_gcode_hashes())
|
|
|
|
|
+
|
|
|
# Register an app-scoped httpx client for Bambu Cloud services so
|
|
# Register an app-scoped httpx client for Bambu Cloud services so
|
|
|
# per-request BambuCloudService instances reuse the same connection pool
|
|
# per-request BambuCloudService instances reuse the same connection pool
|
|
|
# (important for routes like /cloud/filament-info that chain many
|
|
# (important for routes like /cloud/filament-info that chain many
|
|
@@ -12571,6 +12811,8 @@ async def lifespan(app: FastAPI):
|
|
|
stop_auth_cleanup()
|
|
stop_auth_cleanup()
|
|
|
if _plate_estimates_task is not None and not _plate_estimates_task.done():
|
|
if _plate_estimates_task is not None and not _plate_estimates_task.done():
|
|
|
_plate_estimates_task.cancel()
|
|
_plate_estimates_task.cancel()
|
|
|
|
|
+ if _gcode_hashes_task is not None and not _gcode_hashes_task.done():
|
|
|
|
|
+ _gcode_hashes_task.cancel()
|
|
|
from backend.app.services import announcements as announcements_service
|
|
from backend.app.services import announcements as announcements_service
|
|
|
|
|
|
|
|
announcements_service.stop()
|
|
announcements_service.stop()
|