print_queue.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from datetime import datetime
  2. from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, func
  3. from sqlalchemy.orm import Mapped, mapped_column, relationship
  4. from backend.app.core.database import Base
  5. class PrintQueueItem(Base):
  6. """Print queue item for scheduled/queued prints."""
  7. __tablename__ = "print_queue"
  8. id: Mapped[int] = mapped_column(primary_key=True)
  9. # Links
  10. printer_id: Mapped[int | None] = mapped_column(ForeignKey("printers.id", ondelete="CASCADE"), nullable=True)
  11. # Either archive_id OR library_file_id must be set (archive created at print start from library file)
  12. archive_id: Mapped[int | None] = mapped_column(ForeignKey("print_archives.id", ondelete="CASCADE"), nullable=True)
  13. library_file_id: Mapped[int | None] = mapped_column(
  14. ForeignKey("library_files.id", ondelete="CASCADE"), nullable=True
  15. )
  16. project_id: Mapped[int | None] = mapped_column(ForeignKey("projects.id", ondelete="SET NULL"), nullable=True)
  17. # Scheduling
  18. position: Mapped[int] = mapped_column(Integer, default=0) # Queue order
  19. scheduled_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) # None = ASAP
  20. manual_start: Mapped[bool] = mapped_column(Boolean, default=False) # Requires manual trigger to start
  21. # Conditions
  22. require_previous_success: Mapped[bool] = mapped_column(Boolean, default=False)
  23. # Power management
  24. auto_off_after: Mapped[bool] = mapped_column(Boolean, default=False) # Power off printer after print
  25. # AMS mapping: JSON array of global tray IDs for each filament slot
  26. # Format: "[5, -1, 2, -1]" where position = slot_id-1, value = global tray ID (-1 = unused)
  27. ams_mapping: Mapped[str | None] = mapped_column(Text, nullable=True)
  28. # Plate ID for multi-plate 3MF files (1-indexed, None = auto-detect/plate 1)
  29. plate_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
  30. # Print options
  31. bed_levelling: Mapped[bool] = mapped_column(Boolean, default=True)
  32. flow_cali: Mapped[bool] = mapped_column(Boolean, default=False)
  33. vibration_cali: Mapped[bool] = mapped_column(Boolean, default=True)
  34. layer_inspect: Mapped[bool] = mapped_column(Boolean, default=False)
  35. timelapse: Mapped[bool] = mapped_column(Boolean, default=False)
  36. use_ams: Mapped[bool] = mapped_column(Boolean, default=True)
  37. # Status: pending, printing, completed, failed, skipped, cancelled
  38. status: Mapped[str] = mapped_column(String(20), default="pending")
  39. # Tracking
  40. started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
  41. completed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
  42. error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
  43. # Timestamps
  44. created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
  45. # Relationships
  46. printer: Mapped["Printer"] = relationship()
  47. archive: Mapped["PrintArchive | None"] = relationship()
  48. library_file: Mapped["LibraryFile | None"] = relationship()
  49. project: Mapped["Project | None"] = relationship(back_populates="queue_items")
  50. from backend.app.models.archive import PrintArchive # noqa: E402
  51. from backend.app.models.library import LibraryFile # noqa: E402
  52. from backend.app.models.printer import Printer # noqa: E402
  53. from backend.app.models.project import Project # noqa: E402