]> git.ipfire.org Git - pbs.git/commitdiff
builders: Receive stats over the control connection
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Apr 2023 13:44:20 +0000 (13:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Apr 2023 13:44:20 +0000 (13:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/base.py
src/web/builders.py

index 271040ee9007fa3b2c8a09da5412eb2d442326ad..3ed6c25016f904ed75f423218c7e357e67a525f4 100644 (file)
@@ -13,6 +13,7 @@ import tornado.websocket
 import traceback
 
 from .. import __version__
+from .. import builders
 from .. import misc
 from .. import users
 from ..decorators import *
index a0c3e16a5182c6104b9a08288bf9edd3412108f2..1b7d1c99bdb5535b97fc1862708ee5716d1fdd25 100644 (file)
@@ -17,12 +17,27 @@ class APIv1ControlHandler(base.APIMixin, tornado.websocket.WebSocketHandler):
                # Drop the connection to the builder
                self.current_user.disconnected()
 
-       #def on_message(self, message):
-       #       # Decode message
-       #       message = self._decode_json_message(message)
-       #
-       #       with self.db.transaction():
-       #               self.current_user.log_stats(**message)
+       def on_message(self, message):
+               # Decode message
+               message = self._decode_json_message(message)
+
+               # Fetch the message type
+               type = message.get("type")
+
+               # Handle stats
+               if type == "stats":
+                       self._handle_stats(message)
+
+               # Log an error and ignore any other messages
+               else:
+                       log.error("Received message of type '%s' which we cannot handle here" % type)
+
+       def _handle_stats(self, message):
+               """
+                       Handles stats messages
+               """
+               with self.db.transaction():
+                       self.builder.log_stats(**message)
 
 
 class BuilderListHandler(base.BaseHandler):