diff py/uploader.py @ 294:6bacd8ca9f8f

merge
author Matt Johnston <matt@ucc.asn.au>
date Sat, 06 Jul 2019 18:30:25 +0800
parents d15dda1b1f76 78c542f03030
children ca06059e76de
line wrap: on
line diff
--- a/py/uploader.py	Sat Jul 06 18:29:45 2019 +0800
+++ b/py/uploader.py	Sat Jul 06 18:30:25 2019 +0800
@@ -15,6 +15,7 @@
 class Uploader(object):
     def __init__(self, server):
         self.server = server
+        self.limitlog = utils.NotTooOften(600)
 
     @asyncio.coroutine
     def run(self):
@@ -43,6 +44,9 @@
 
         return tosend
 
+    class BadServerResponse(Exception):
+        pass
+
     @asyncio.coroutine
     def send(self, tosend):
         js = json.dumps(tosend)
@@ -55,7 +59,7 @@
         r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60)
         result = yield from asyncio.wait_for(r.text(), 60)
         if r.status == 200 and result != 'OK':
-            raise Exception("Server returned %s" % result)
+            raise BadServerResponse("Server returned %s" % result)
 
     @asyncio.coroutine
     def do(self):
@@ -67,6 +71,12 @@
             yield from self.send(tosend)
             readings = None
             D("Sent updated %d readings" % nreadings)
+        except aiohttp.errors.ClientError as e:
+            self.limitlog.log("Error with uploader: %s" % str(e))
+        except asyncio.TimeoutError as e:
+            self.limitlog.log("uploader http timed out: %s" % str(e))
+        except self.BadServerResponse as e:
+            self.limitlog.log("Bad reply with uploader: %s" % str(e))
         except Exception as e:
             EX("Error in uploader: %s" % str(e))
         finally: