Wrap Google Fit checks in try-catch block to prevent the backend from crashing with no reload
This commit is contained in:
parent
7072a19829
commit
92f1f3eea7
1 changed files with 33 additions and 28 deletions
|
@ -66,40 +66,45 @@ class GoogleFitBackend(Backend):
|
||||||
self.logger.info('Scanning fit data source, last seen timestamp: {}'.
|
self.logger.info('Scanning fit data source, last seen timestamp: {}'.
|
||||||
format(str(datetime.datetime.fromtimestamp(last_timestamp))))
|
format(str(datetime.datetime.fromtimestamp(last_timestamp))))
|
||||||
|
|
||||||
for data_source in self.data_sources:
|
try:
|
||||||
data_source_last_timestamp = 0
|
for data_source in self.data_sources:
|
||||||
data_points = get_plugin('google.fit').get_data(
|
data_source_last_timestamp = 0
|
||||||
user_id=self.user_id, data_source_id=data_source).output
|
data_points = get_plugin('google.fit').get_data(
|
||||||
|
user_id=self.user_id, data_source_id=data_source).output
|
||||||
|
|
||||||
for dp in data_points:
|
for dp in data_points:
|
||||||
dp_time = dp.pop('startTime', 0)
|
dp_time = dp.pop('startTime', 0)
|
||||||
if 'dataSourceId' in dp:
|
if 'dataSourceId' in dp:
|
||||||
del dp['dataSourceId']
|
del dp['dataSourceId']
|
||||||
|
|
||||||
if dp_time > last_timestamp:
|
if dp_time > last_timestamp:
|
||||||
self.bus.post(GoogleFitEvent(
|
self.bus.post(GoogleFitEvent(
|
||||||
user_id=self.user_id, data_source_id=data_source,
|
user_id=self.user_id, data_source_id=data_source,
|
||||||
data_type=dp.pop('dataTypeName'),
|
data_type=dp.pop('dataTypeName'),
|
||||||
start_time=dp_time,
|
start_time=dp_time,
|
||||||
end_time=dp.pop('endTime'),
|
end_time=dp.pop('endTime'),
|
||||||
modified_time=dp.pop('modifiedTime'),
|
modified_time=dp.pop('modifiedTime'),
|
||||||
values=dp.pop('values'),
|
values=dp.pop('values'),
|
||||||
**{ camel_case_to_snake_case(k): v
|
**{ camel_case_to_snake_case(k): v
|
||||||
for k,v in dp.items() }
|
for k,v in dp.items() }
|
||||||
))
|
))
|
||||||
|
|
||||||
new_last_timestamp = max(dp_time, new_last_timestamp)
|
new_last_timestamp = max(dp_time, new_last_timestamp)
|
||||||
data_source_last_timestamp = max(dp_time, data_source_last_timestamp)
|
data_source_last_timestamp = max(dp_time, data_source_last_timestamp)
|
||||||
|
|
||||||
self.logger.info('Got {} entries from data source {}, last timestamp: {}'.
|
self.logger.info('Got {} entries from data source {}, last timestamp: {}'.
|
||||||
format(len(data_points), data_source,
|
format(len(data_points), data_source,
|
||||||
str(datetime.datetime.fromtimestamp(data_source_last_timestamp))))
|
str(datetime.datetime.fromtimestamp(data_source_last_timestamp))))
|
||||||
|
last_timestamp = new_last_timestamp
|
||||||
|
|
||||||
|
get_plugin('variable').set(**{
|
||||||
|
self._last_timestamp_varname: last_timestamp})
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warning('Exception while processing Fit data')
|
||||||
|
self.logger.exception(e)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
last_timestamp = new_last_timestamp
|
|
||||||
|
|
||||||
get_plugin('variable').set(**{
|
|
||||||
self._last_timestamp_varname: last_timestamp})
|
|
||||||
time.sleep(self.poll_seconds)
|
time.sleep(self.poll_seconds)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue