Add configurable delay per client; improve try/catch

This commit is contained in:
Lance Edgar 2017-02-07 14:47:57 -06:00
parent 3f9adfa6c5
commit 4e11748b45
5 changed files with 97 additions and 58 deletions

View file

@ -66,37 +66,35 @@ class TempmonClient(Daemon):
session.close()
raise ConfigurationError("No tempmon client configured for hostname: {}".format(hostname))
client_uuid = client.uuid
self.delay = client.delay or 60
session.close()
# main loop: take readings, pause, repeat
while True:
session = Session()
client = session.query(tempmon.Client).get(client_uuid)
if client.enabled:
try:
session = Session()
try:
client = session.query(tempmon.Client).get(client_uuid)
self.delay = client.delay or 60
if client.enabled:
for probe in client.enabled_probes():
self.take_reading(session, probe)
except:
log.exception("Failed to read/record temperature data")
session.rollback()
raise
else:
# make sure we show as being online
if not client.online:
client.online = True
session.commit()
finally:
session.close()
except:
log.exception("Failed to read/record temperature data (but will keep trying)")
session.rollback()
else:
# make sure we show as being online
if not client.online:
client.online = True
session.commit()
finally:
session.close()
# TODO: make this configurable
time.sleep(60)
time.sleep(self.delay)
def take_reading(self, session, probe):
"""