# Module: ai_availability_status ## Purpose Thread-safe status tracker for the AI engine lifecycle (downloading, converting, uploading, enabled, warning, error). ## Public Interface ### Enum: AIAvailabilityEnum | Value | Name | Meaning | |-------|------|---------| | 0 | NONE | Initial state, not yet initialized | | 10 | DOWNLOADING | Model download in progress | | 20 | CONVERTING | ONNX-to-TensorRT conversion in progress | | 30 | UPLOADING | Converted model upload in progress | | 200 | ENABLED | Engine ready for inference | | 300 | WARNING | Operational with warnings | | 500 | ERROR | Failed, not operational | ### Class: AIAvailabilityStatus | Field | Type | Description | |-------|------|-------------| | `status` | AIAvailabilityEnum | Current status | | `error_message` | str or None | Error/warning details | | Method | Signature | Description | |--------|-----------|-------------| | `__init__` | `()` | Sets status=NONE, error_message=None | | `__str__` | `() -> str` | Thread-safe formatted string: `"StatusText ErrorText"` | | `serialize` | `() -> bytes` | Thread-safe msgpack serialization `{s: status, m: error_message}` **(legacy — not called in current codebase)** | | `set_status` | `(AIAvailabilityEnum status, str error_message=None) -> void` | Thread-safe status update; logs via constants_inf (error or info) | ## Internal Logic All public methods acquire a `threading.Lock` before reading/writing status fields. `set_status` logs the transition: errors go to `constants_inf.logerror`, normal transitions go to `constants_inf.log`. ## Dependencies - **External**: `msgpack`, `threading` - **Internal**: `constants_inf` (logging) ## Consumers - `inference` — creates instance, calls `set_status` during engine lifecycle, exposes `ai_availability_status` for health checks - `main` — reads `ai_availability_status` via inference for `/health` endpoint ## Data Models - `AIAvailabilityEnum` — status enum - `AIAvailabilityStatus` — stateful status holder ## Configuration None. ## External Integrations None. ## Security Thread-safe via Lock — safe for concurrent access from FastAPI async + ThreadPoolExecutor. ## Tests None found.