Fix exception handler in _write_statistics
@@ -64,12 +64,14 @@ class SensorValues(aiocoap.resource.Resource):
async def _update_statistics(self):
while True:
await asyncio.sleep(5)
+
+ try:
readings = self._num_readings
self._num_readings = 0
try:
await statistics.update_statistics_value('READINGS', readings)
except Exception:
- self._num_readings = readings
+ self._num_readings += readings
raise
readings = self._num_discarded_readings
self._num_discarded_readings = 0
@@ -78,6 +80,9 @@ class SensorValues(aiocoap.resource.Resource):
except Exception:
self._num_discarded_readings += readings
raise
+ except Exception:
+ logging.getLogger('coap-server').exception(
+ 'An error occurred while updating statistics')
async def render_post(self, request):
"""Sends asset readings to storage layer
