From: Michael Tremer Date: Wed, 26 Apr 2023 13:44:20 +0000 (+0000) Subject: builders: Receive stats over the control connection X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61428bcefd0a8db7a38681e118f99375bb449086;p=pbs.git builders: Receive stats over the control connection Signed-off-by: Michael Tremer --- diff --git a/src/web/base.py b/src/web/base.py index 271040ee..3ed6c250 100644 --- a/src/web/base.py +++ b/src/web/base.py @@ -13,6 +13,7 @@ import tornado.websocket import traceback from .. import __version__ +from .. import builders from .. import misc from .. import users from ..decorators import * diff --git a/src/web/builders.py b/src/web/builders.py index a0c3e16a..1b7d1c99 100644 --- a/src/web/builders.py +++ b/src/web/builders.py @@ -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):