comparison mqtt_io.py @ 27:32cfefe3155b

try harder to crash if there's an mqtt error, so k8s does a full restart
author drewp@bigasterisk.com
date Sat, 23 Mar 2024 15:25:02 -0700
parents e3dbd04dab96
children
comparison
equal deleted inserted replaced
26:33b3eb24506e 27:32cfefe3155b
1 import asyncio 1 import asyncio
2 import inspect 2 import inspect
3 import json 3 import json
4 import logging 4 import logging
5 import os
5 import time 6 import time
6 from typing import Callable, cast 7 from typing import Callable, cast
7 import weakref 8 import weakref
8 9
9 import aiomqtt # v 2.0.0 10 import aiomqtt # v 2.0.0
107 try: 108 try:
108 await self._connectAndRead() 109 await self._connectAndRead()
109 except aiomqtt.MqttError as e: 110 except aiomqtt.MqttError as e:
110 MQTT_CONNECTED.set(0) 111 MQTT_CONNECTED.set(0)
111 log.error(e, exc_info=True) 112 log.error(e, exc_info=True)
113 os.abort()
112 114
113 async def _connectAndRead(self): 115 async def _connectAndRead(self):
114 async with self.client: 116 async with self.client:
115 await self.subs.onMqttConnected() 117 await self.subs.onMqttConnected()
116 MQTT_CONNECTED.set(1) 118 MQTT_CONNECTED.set(1)