forked from platypush/platypush
Implemented retry mechanism in sensor backend
This commit is contained in:
parent
76800e00b1
commit
52a13f0511
1 changed files with 19 additions and 8 deletions
|
@ -82,15 +82,26 @@ class SensorBackend(Backend):
|
||||||
if not self.plugin:
|
if not self.plugin:
|
||||||
raise NotImplementedError('No plugin specified')
|
raise NotImplementedError('No plugin specified')
|
||||||
|
|
||||||
plugin = get_plugin(self.plugin)
|
reload = False
|
||||||
data = plugin.get_data(**self.plugin_args).output
|
success = False
|
||||||
|
data = None
|
||||||
|
|
||||||
if self.enabled_sensors:
|
while not success:
|
||||||
data = {
|
try:
|
||||||
sensor: data[sensor]
|
plugin = get_plugin(self.plugin, reload=reload)
|
||||||
for sensor, enabled in self.enabled_sensors.items()
|
data = plugin.get_data(**self.plugin_args).output
|
||||||
if enabled and sensor in data
|
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
|
return data
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue