projects
/
saartuer.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
send an email when updating the SpaceAI consistently fails
[saartuer.git]
/
spaceapi.py
diff --git
a/spaceapi.py
b/spaceapi.py
index eea73f6a2a708fb3061617527e60fb10a76207f7..7f788ab4b32aee8897b48f60e2f944139c28069f 100644
(file)
--- a/
spaceapi.py
+++ b/
spaceapi.py
@@
-4,7
+4,7
@@
import urllib.request, time
from config import spaceApiKey
from config import spaceApiKey
-RETRY_TIME =
3
0
+RETRY_TIME =
6
0
HEARTBEAT_TIME = 10*60
class SpaceApi:
HEARTBEAT_TIME = 10*60
class SpaceApi:
@@
-13,6
+13,7
@@
class SpaceApi:
self._remote_state = None
self._last_set_at = 0
self._running = True
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)
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)
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
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)