except KeyError:
return
- async def join(self, job, consumer):
+ async def join(self, job, consumer, **kwargs):
"""
Joins the stream for the given job
"""
return
# Join the stream
- await stream.join(consumer)
+ await stream.join(consumer, **kwargs)
return stream
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
"""
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))
// Use the code font
font-family: $family-code;
+ // Break loglines like a terminal would
+ overflow-wrap: break-word;
+
// Keep any whitespace
white-space: pre;
background-color: $danger;
color: $danger-invert;
}
+
+ &.is-small {
+ font-size: $size-small;
+ text-overflow: ellipsis;
+ }
}
/*
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);
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();
}
-<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>
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)
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 [