feat(printer): badge print queue, Pi worker, captive-portal setup, admin printing view
- migration 20261018170000: pgmq badge_print/badge_print_dlq, print_stations, token-gated printer RPCs (claim/complete/fail/heartbeat), admin RPCs, welcome_checkin enqueue; badge_print_tests.sql (101 assertions) - apps/printer: Python worker (Playwright render -> brother_ql via pyusb), comitup captive-portal (Wi-Fi + HTTPS endpoint + anon key + token), arm64 image build + idempotent Pi setup/install scripts, 77 pytest - apps/admin: Printing view, station management/DLQ, global printer status pill, Print button on Registrations, standalone print renderer entry (print.html -> dist-print) with bundled fonts - docs: printing.md + architecture/schema/rpcs/tests/admin-app updates, apps/printer/AGENT.md operating manual - e2e: printing.spec.ts
This commit is contained in:
1 parent
04f3f55b78
commit
c980effddc
55 files changed
+7406
-29
No files matched your search
@@ -0,0 +1,81 @@
|
||||
"""Environment-driven configuration for the badge-printer worker."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
def _int(name: str, default: int) -> int:
|
||||
raw = os.environ.get(name, "").strip()
|
||||
try:
|
||||
return int(raw) if raw else default
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
|
||||
def _flag(name: str, default: str = "0") -> bool:
|
||||
return os.environ.get(name, default).strip().lower() in ("1", "true", "yes", "on")
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
convivo_url: str
|
||||
convivo_anon_key: str
|
||||
station_name: str = "Welcome desk"
|
||||
checkin_origin: str = "https://admin.appe.at"
|
||||
brother_model: str = "QL-1110NWB"
|
||||
brother_label: str = "auto"
|
||||
printer_identifier: str = "usb://0x04f9:0x20a8"
|
||||
dry_run: bool = False
|
||||
# Ready / no-network labels cost media; the admin status pill is the default channel.
|
||||
status_labels: bool = False
|
||||
heartbeat_seconds: int = 10
|
||||
vt_seconds: int = 120
|
||||
wait_seconds: int = 2
|
||||
network_state_file: str = "/run/convivo/network.json"
|
||||
renderer_dir: str = "/app/renderer"
|
||||
threshold: int = 70
|
||||
dither: bool = False
|
||||
app_version: str = "dev"
|
||||
# Token kept out of repr so it can never reach a log line.
|
||||
station_token: str = field(default="", repr=False)
|
||||
|
||||
@classmethod
|
||||
def from_env(cls) -> "Config":
|
||||
url = os.environ.get("CONVIVO_URL", "").strip().rstrip("/")
|
||||
anon = os.environ.get("CONVIVO_ANON_KEY", "").strip()
|
||||
token = os.environ.get("PRINTER_STATION_TOKEN", "").strip()
|
||||
missing = [
|
||||
name
|
||||
for name, value in (
|
||||
("CONVIVO_URL", url),
|
||||
("CONVIVO_ANON_KEY", anon),
|
||||
("PRINTER_STATION_TOKEN", token),
|
||||
)
|
||||
if not value
|
||||
]
|
||||
if missing:
|
||||
raise RuntimeError(f"missing required env: {', '.join(missing)}")
|
||||
return cls(
|
||||
convivo_url=url,
|
||||
convivo_anon_key=anon,
|
||||
station_token=token,
|
||||
station_name=os.environ.get("STATION_NAME", "Welcome desk").strip()
|
||||
or "Welcome desk",
|
||||
checkin_origin=os.environ.get("BADGE_CHECKIN_ORIGIN", "https://admin.appe.at")
|
||||
.strip()
|
||||
.rstrip("/"),
|
||||
brother_model=os.environ.get("BROTHER_MODEL", "QL-1110NWB").strip(),
|
||||
brother_label=os.environ.get("BROTHER_LABEL", "auto").strip() or "auto",
|
||||
printer_identifier=os.environ.get("PRINTER_IDENTIFIER", "usb://0x04f9:0x20a8").strip(),
|
||||
dry_run=_flag("DRY_RUN"),
|
||||
status_labels=_flag("STATUS_LABELS"),
|
||||
heartbeat_seconds=_int("HEARTBEAT_SECONDS", 10),
|
||||
vt_seconds=_int("VT_SECONDS", 120),
|
||||
wait_seconds=_int("WAIT_SECONDS", 2),
|
||||
network_state_file=os.environ.get("NETWORK_STATE_FILE", "/run/convivo/network.json"),
|
||||
renderer_dir=os.environ.get("RENDERER_DIR", "/app/renderer"),
|
||||
threshold=_int("THRESHOLD", 70),
|
||||
dither=_flag("DITHER"),
|
||||
app_version=os.environ.get("APP_VERSION", "dev").strip() or "dev",
|
||||
)
|
||||
Reference in new issue
Block a user