hms_notified_fault.py 1.2 KB

1234567891011121314151617181920212223242526272829
  1. """HMS faults a notification has already gone out for, per printer (#3486).
  2. The printer keeps faults in its ``hms[]`` list long after they happened, and
  3. the de-duplication that stops them being sent again lived only in memory: every
  4. Bambuddy restart sent each still-listed fault once more. Kept here so a restart
  5. picks up where it left off. Only the set of fault keys is stored; when each was
  6. last seen stays in memory.
  7. """
  8. from __future__ import annotations
  9. from datetime import datetime
  10. from sqlalchemy import DateTime, ForeignKey, Integer, String, UniqueConstraint, func
  11. from sqlalchemy.orm import Mapped, mapped_column
  12. from backend.app.core.database import Base
  13. class HmsNotifiedFault(Base):
  14. __tablename__ = "hms_notified_faults"
  15. __table_args__ = (UniqueConstraint("printer_id", "fault_key", name="uq_hms_notified_faults_printer_fault"),)
  16. id: Mapped[int] = mapped_column(primary_key=True)
  17. printer_id: Mapped[int] = mapped_column(
  18. Integer, ForeignKey("printers.id", ondelete="CASCADE"), nullable=False, index=True
  19. )
  20. fault_key: Mapped[str] = mapped_column(String(64), nullable=False)
  21. created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())