changeset 1491:c0742e710eeb

refactor collector json parsing Ignore-this: ae540a86d86ff9a45e5b2b66ee5f82d4
author drewp@bigasterisk.com
date Mon, 13 Jun 2016 19:25:00 +0000
parents 649d482737e0
children ce97f298bfb8
files bin/collector
diffstat 1 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/bin/collector	Mon Jun 13 17:36:38 2016 +0000
+++ b/bin/collector	Mon Jun 13 19:25:00 2016 +0000
@@ -19,6 +19,13 @@
 from light9.rdfdb.syncedgraph import SyncedGraph
 from light9.rdfdb import clientsession
 
+def parseJsonMessage(msg):
+    body = json.load(msg)
+    settings = []
+    for device, attr, value in body['settings']:
+        settings.append((URIRef(device), URIRef(attr), Literal(value)))
+    return body['client'], body['clientSession'], settings, body['sendTime']
+
 class WebServer(object):
     stats = scales.collection('/webServer',
                               scales.PmfStat('setAttr'))
@@ -29,14 +36,8 @@
     @app.route('/attrs', methods=['PUT'])
     def putAttrs(self, request):
         with WebServer.stats.setAttr.time():
-            body = json.load(request.content)
-            settings = []
-            for device, attr, value in body['settings']:
-                settings.append((URIRef(device), URIRef(attr), Literal(value)))
-            self.collector.setAttrs(body['client'],
-                                    body['clientSession'],
-                                    settings,
-                                    body['sendTime'])
+            client, clientSession, settings, sendTime = parseJsonMessage(request.content)
+            self.collector.setAttrs(client, clientSession, settings, sendTime)
             request.setResponseCode(202)
 
     @app.route('/stats', methods=['GET'])