Execution Model
1. Boot Sequence (Main.ts)â
2. MQTT Message Processing Pipelineâ
3. Command Dispatch Lifecycleâ
4. WebSocket State Propagationâ
5. Background Job Executionâ
| Job | Trigger | Interval | Implementation |
|---|---|---|---|
| Command Sweeper | setInterval | 30s | Queries commands where status=dispatched AND created_at < cutoff. Batch updates to expired. |
| Heartbeat Monitor | setInterval | Configurable | Checks Redis TTL keys per device. If expired â marks device offline, triggers OTA check. |
| Email Worker | BullMQ consumer | Continuous | 5 concurrent workers, 50/min rate limit, exponential backoff à 5 attempts. Dead-letter on exhaustion. |
| HX47 Health Check | setInterval | 5s | Checks heartbeat timestamp gap. 3 consecutive failures â attempt restart with backoff (max 5). |