From 26ec213098b0e09bbd6789aa005eb69bb7b35f16 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 6 Nov 2018 11:40:01 +0100 Subject: [PATCH] Make sure that the shitty MQTT backend doesn't break for no reason --- platypush/backend/mqtt.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/platypush/backend/mqtt.py b/platypush/backend/mqtt.py index 952c5898e9..2a26fd7fff 100644 --- a/platypush/backend/mqtt.py +++ b/platypush/backend/mqtt.py @@ -79,14 +79,17 @@ class MqttBackend(Backend): def send_message(self, msg): - client = get_plugin('mqtt') - client.send_message(topic=self.topic, msg=msg, host=self.host, - port=self.port, username=self.username, - password=self.password, tls_cafile=self.tls_cafile, - tls_certfile=self.tls_certfile, - tls_keyfile=self.tls_keyfile, - tls_version=self.tls_version, - tls_ciphers=self.tls_ciphers) + try: + client = get_plugin('mqtt') + client.send_message(topic=self.topic, msg=msg, host=self.host, + port=self.port, username=self.username, + password=self.password, tls_cafile=self.tls_cafile, + tls_certfile=self.tls_certfile, + tls_keyfile=self.tls_keyfile, + tls_version=self.tls_version, + tls_ciphers=self.tls_ciphers) + except Exception as e: + self.logger.exception(e) def run(self): def on_connect(client, userdata, flags, rc): @@ -100,21 +103,18 @@ class MqttBackend(Backend): self.logger.info('Processing response on the MQTT topic {}: {}'. format(response_topic, response)) - client = get_plugin('mqtt') - client.send_message(topic=self.topic, msg=response, host=self.host, - port=self.port, username=self.username, - password=self.password, tls_cafile=self.tls_cafile, - tls_certfile=self.tls_certfile, - tls_keyfile=self.tls_keyfile, - tls_version=self.tls_version, - tls_ciphers=self.tls_ciphers) + self.send_message(response) msg = msg.payload.decode('utf-8') try: msg = Message.build(json.loads(msg)) except: pass self.logger.info('Received message on the MQTT backend: {}'.format(msg)) - self.on_message(msg) + + try: + self.on_message(msg) + except Exception as e: + self.logger.exception(e) if isinstance(msg, Request): threading.Thread(target=response_thread, args=(msg,)).start()