]> git.ipfire.org Git - pbs.git/commitdiff
log-stream: Allow sending how many initial lines we want to receive
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 May 2023 15:58:24 +0000 (15:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 May 2023 15:58:24 +0000 (15:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/logstreams.py
src/static/css/site.scss
src/static/js/job-log-stream.js
src/templates/jobs/modules/log-stream.html
src/web/jobs.py

index 0f89c6a72ba1d0b18d90c91966705e1562bbc6b2..c957e2d064da002929c564b1390fd5990d03dbb7 100644 (file)
@@ -51,7 +51,7 @@ class LogStreams(base.Object):
                except KeyError:
                        return
 
-       async def join(self, job, consumer):
+       async def join(self, job, consumer, **kwargs):
                """
                        Joins the stream for the given job
                """
@@ -61,7 +61,7 @@ class LogStreams(base.Object):
                        return
 
                # Join the stream
-               await stream.join(consumer)
+               await stream.join(consumer, **kwargs)
 
                return stream
 
@@ -97,7 +97,7 @@ class LogStream(base.Object):
                for consumer in self.consumers:
                        consumer.close()
 
-       async def join(self, consumer):
+       async def join(self, consumer, limit=None):
                """
                        Called when a consumer wants to receive the stream
                """
@@ -105,7 +105,12 @@ class LogStream(base.Object):
                self.consumers.append(consumer)
 
                # Send all messages in the buffer
-               for message in self.buffer:
+               for i, message in enumerate(self.buffer):
+                       # Only sent up to limit messages
+                       if limit and i >= limit:
+                               break
+
+                       # Send the message
                        await consumer.message(message)
 
                log.debug("%s has joined the stream for %s" % (consumer, self.job))
index e34dc18f3a1d1c072b05fcfea115d78bd68b9e30..be121e8e2c143d4ecd4be91d3ee8aa289718e76e 100644 (file)
@@ -48,6 +48,9 @@ html, body {
        // Use the code font
        font-family: $family-code;
 
+       // Break loglines like a terminal would
+       overflow-wrap: break-word;
+
        // Keep any whitespace
        white-space: pre;
 
@@ -69,6 +72,11 @@ html, body {
                background-color: $danger;
                color: $danger-invert;
        }
+
+       &.is-small {
+               font-size: $size-small;
+               text-overflow: ellipsis;
+       }
 }
 
 /*
index 0d5e015bb1371661c598298c3e09782c42464705..94a20f8a567abbf54ff8d7e4c994b59dc740f3b8 100644 (file)
@@ -9,7 +9,10 @@ $(".jobs-log-stream").each(function() {
        const log = $(this);
 
        // Make the URL
-       const url = "wss://" + window.location.host + "/api/v1/jobs/" + uuid + "/log/stream";
+       var url = "wss://" + window.location.host + "/api/v1/jobs/" + uuid + "/log/stream";
+
+       if (limit > 0)
+               url += "?limit=" + limit;
 
        // Try to connect to the stream
        const stream = new WebSocket(url);
@@ -21,7 +24,7 @@ $(".jobs-log-stream").each(function() {
                console.log("Message from server: ", data);
 
                // If there is a limit, reduce the number of rows first
-               while (limit > 0 && log.children().length > limit) {
+               while (limit > 0 && log.children().length >= limit) {
                        log.children().first().remove();
                }
 
index 362374261d272ad41a2fc314e12ef09f75609ecc..6cb93f6a06f4d0fca5b6b2f2f788fe4139e7a55f 100644 (file)
@@ -1,2 +1,2 @@
-<ul class="jobs-log-stream" data-uuid="{{ job.uuid }}"
-       {% if limit %}data-limit="{{ limit }}"{% end %}></ul>
+<ul class="jobs-log-stream {% if small %}is-small{% end %}"
+       data-uuid="{{ job.uuid }}" {% if limit %}data-limit="{{ limit }}"{% end %}></ul>
index 5ccd63701a36bfa013dabbcd02006cbf346c9ffa..4e964a190d19d5644730ba254657d2f59826fa05 100644 (file)
@@ -110,8 +110,11 @@ class APIv1LogStreamHandler(base.BackendMixin, tornado.websocket.WebSocketHandle
                if not job:
                        raise tornado.web.HTTPError(404, "Could not find job %s" % uuid)
 
+               # How many messages should be initially sent?
+               limit = self.get_argument_int("limit", None)
+
                # Join the stream
-               self.stream = await self.backend.logstreams.join(job, self)
+               self.stream = await self.backend.logstreams.join(job, self, limit=limit)
                if not self.stream:
                        raise tornado.web.HTTPError(400, "Could not join stream for %s" % job)
 
@@ -230,8 +233,9 @@ class ListModule(ui_modules.UIModule):
 
 
 class LogStreamModule(ui_modules.UIModule):
-       def render(self, job, limit=None):
-               return self.render_string("jobs/modules/log-stream.html", job=job, limit=limit)
+       def render(self, job, limit=None, small=False):
+               return self.render_string("jobs/modules/log-stream.html",
+                       job=job, limit=limit, small=small)
 
        def javascript_files(self):
                return [