From 8220082359abc48e3e2008477b8f6002c5c16ae3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 23 Oct 2018 17:39:18 -0500 Subject: [PATCH] Add try/catch for client's "read temp" logic this can isolate an error for a certain probe, so that other probes can go ahead and take their readings during each client run. that way only the bad one is marked as "error" status by the server --- rattail_tempmon/client.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/rattail_tempmon/client.py b/rattail_tempmon/client.py index 9fde68a..f8694b5 100644 --- a/rattail_tempmon/client.py +++ b/rattail_tempmon/client.py @@ -137,22 +137,28 @@ class TempmonClient(Daemon): Take a single reading and add to Rattail database. """ reading = tempmon.Reading() - reading.degrees_f = self.read_temp(probe) - # a reading of 185.0 °F indicates some sort of power issue. when this - # happens we log an error (which sends basic email) but do not record - # the temperature. that way the server doesn't see the 185.0 reading - # and send out a "false alarm" about the temperature being too high. - # https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html - if reading.degrees_f == 185.0: - log.error("got reading of 185.0 from probe: %s", probe.description) + try: + reading.degrees_f = self.read_temp(probe) - else: # we have a good reading - reading.client = probe.client - reading.probe = probe - reading.taken = datetime.datetime.utcnow() - session.add(reading) - return reading + except: + log.exception("Failed to read temperature (but will keep trying) for probe: %s", probe) + + else: + # a reading of 185.0 °F indicates some sort of power issue. when this + # happens we log an error (which sends basic email) but do not record + # the temperature. that way the server doesn't see the 185.0 reading + # and send out a "false alarm" about the temperature being too high. + # https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html + if reading.degrees_f == 185.0: + log.error("got reading of 185.0 from probe: %s", probe.description) + + else: # we have a good reading + reading.client = probe.client + reading.probe = probe + reading.taken = datetime.datetime.utcnow() + session.add(reading) + return reading def read_temp(self, probe): """