From dfd60ef69a6fa4b790250431f9b7fde6da084ec9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Nov 2013 13:49:44 +0100 Subject: [PATCH] send an email when updating the SpaceAI consistently fails --- spaceapi.py | 7 ++++++- tuerd | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spaceapi.py b/spaceapi.py index 8e36b0f..7f788ab 100644 --- a/spaceapi.py +++ b/spaceapi.py @@ -13,6 +13,7 @@ class SpaceApi: self._remote_state = None self._last_set_at = 0 self._running = True + self._fail_count = 0 # number of consecutive fails self.set_state = ThreadFunction(self._set_state, "Space API") waker.register(self.set_state, RETRY_TIME) @@ -44,7 +45,11 @@ class SpaceApi: if self._local_state is not None and (self._local_state != self._remote_state or now > self._last_set_at+HEARTBEAT_TIME): # take action! success = self._do_request(self._local_state) - # TODO error too often -> log critical to send mails if success: self._remote_state = self._local_state self._last_set_at = now + self._fail_count = 0 + else: + self._fail_count += 1 + if self._fail_count in (5, 50, 500): + logger.critical("Updating the SpaceAPI failed %d times in a row" % self._fail_count) diff --git a/tuerd b/tuerd index c0b4413..942c495 100755 --- a/tuerd +++ b/tuerd @@ -43,7 +43,7 @@ except KeyboardInterrupt: # this is what we waited for! pass -logger.info("Terminating...") +logger.info("Terminating...") # somehow this does not arrive in the syslog # bring 'em all down the_waker.stop() # this one first, it "randomly" calls other threads -- 2.30.2