From 52a13f051147ee5a5cbe2799e92c68dffaf52510 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 26 Feb 2020 11:12:46 +0100 Subject: [PATCH] Implemented retry mechanism in sensor backend --- platypush/backend/sensor/__init__.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/platypush/backend/sensor/__init__.py b/platypush/backend/sensor/__init__.py index 3902de8792..f265ccf707 100644 --- a/platypush/backend/sensor/__init__.py +++ b/platypush/backend/sensor/__init__.py @@ -82,15 +82,26 @@ class SensorBackend(Backend): if not self.plugin: raise NotImplementedError('No plugin specified') - plugin = get_plugin(self.plugin) - data = plugin.get_data(**self.plugin_args).output + reload = False + success = False + data = None - if self.enabled_sensors: - data = { - sensor: data[sensor] - for sensor, enabled in self.enabled_sensors.items() - if enabled and sensor in data - } + while not success: + try: + plugin = get_plugin(self.plugin, reload=reload) + data = plugin.get_data(**self.plugin_args).output + except Exception as e: + self.logger.warning('Unexpected exception while getting data: {}'.format(str(e))) + self.logger.exception(e) + reload = True + time.sleep(5) + + if self.enabled_sensors: + data = { + sensor: data[sensor] + for sensor, enabled in self.enabled_sensors.items() + if enabled and sensor in data + } return data