mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-29 13:30:26 -07:00
Transparently restart monitoring tasks that fail
This commit is contained in:
parent
d7cadd09c5
commit
172c755f95
15
wideq.py
15
wideq.py
@ -359,7 +359,12 @@ class Session(object):
|
|||||||
|
|
||||||
|
|
||||||
class Monitor(object):
|
class Monitor(object):
|
||||||
"""A monitoring task for a device."""
|
"""A monitoring task for a device.
|
||||||
|
|
||||||
|
This task is robust to some API-level failures. If the monitoring
|
||||||
|
task expires, it attempts to start a new one automatically. This
|
||||||
|
makes one `Monitor` object suitable for long-term monitoring.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, session, device_id):
|
def __init__(self, session, device_id):
|
||||||
self.session = session
|
self.session = session
|
||||||
@ -376,7 +381,13 @@ class Monitor(object):
|
|||||||
device is not yet ready.
|
device is not yet ready.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.session.monitor_poll(self.device_id, self.work_id)
|
try:
|
||||||
|
return self.session.monitor_poll(self.device_id, self.work_id)
|
||||||
|
except MonitorError:
|
||||||
|
# Try to restart the task.
|
||||||
|
self.stop()
|
||||||
|
self.start()
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decode_json(data):
|
def decode_json(data):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user