add probatory exception trigger in mqtt connection handling
All checks were successful
Build Container / Build Container (push) Successful in 4m15s
All checks were successful
Build Container / Build Container (push) Successful in 4m15s
This commit is contained in:
parent
ab61ee3926
commit
300e773ccd
1 changed files with 13 additions and 3 deletions
|
|
@ -3,14 +3,13 @@
|
||||||
# https://github.com/eclipse-paho/paho.mqtt.python/blob/master/examples/loop_asyncio.py
|
# https://github.com/eclipse-paho/paho.mqtt.python/blob/master/examples/loop_asyncio.py
|
||||||
#
|
#
|
||||||
|
|
||||||
from typing import Any, Set, Iterable
|
|
||||||
import logging
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
from typing import Any, Iterable, Set
|
||||||
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -109,9 +108,20 @@ class AsyncMqttClient:
|
||||||
properties: mqtt.Properties,
|
properties: mqtt.Properties,
|
||||||
):
|
):
|
||||||
logger.debug(f"mqtt client disconnected with message '{reason_code}'")
|
logger.debug(f"mqtt client disconnected with message '{reason_code}'")
|
||||||
|
|
||||||
if self.fut_disconnect:
|
if self.fut_disconnect:
|
||||||
self.fut_disconnect.set_result(None)
|
self.fut_disconnect.set_result(None)
|
||||||
|
|
||||||
|
# this should not be needed since we have an on_connect_fail callback but logs suggest it to be needed
|
||||||
|
# TODO: investigate whether dooris is now more able to keep its connections
|
||||||
|
if self.fut_connected is not None:
|
||||||
|
logger.debug(
|
||||||
|
f"triggering exceptional failure in connection future from disconnect. this shouldn't happen."
|
||||||
|
)
|
||||||
|
self.fut_connected.set_exception(
|
||||||
|
Exception("mqtt client could not connect to broker")
|
||||||
|
)
|
||||||
|
|
||||||
def on_message(self, client: mqtt.Client, userdata: Any, msg: mqtt.MQTTMessage):
|
def on_message(self, client: mqtt.Client, userdata: Any, msg: mqtt.MQTTMessage):
|
||||||
self.messages.put_nowait(msg)
|
self.messages.put_nowait(msg)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue