From: Michael Tremer Date: Mon, 8 May 2023 15:46:43 +0000 (+0000) Subject: jobs: Add log stream to the listing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88577b50f0caab47777dde9a1c855e467dd737a4;p=pbs.git jobs: Add log stream to the listing Signed-off-by: Michael Tremer --- diff --git a/src/static/js/job-log-stream.js b/src/static/js/job-log-stream.js index f2fb830e..0d5e015b 100644 --- a/src/static/js/job-log-stream.js +++ b/src/static/js/job-log-stream.js @@ -2,6 +2,9 @@ $(".jobs-log-stream").each(function() { // Fetch the UUID of the job const uuid = $(this).data("uuid"); + // Fetch the limit + const limit = $(this).data("limit"); + // Find where we are appending lines to const log = $(this); @@ -17,8 +20,13 @@ $(".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) { + log.children().first().remove(); + } + // Create a new line - var line = $("

"); + var line = $("
  • "); // Set the log level line.addClass(data.level); diff --git a/src/templates/jobs/modules/list.html b/src/templates/jobs/modules/list.html index 16e313ed..ea61ed71 100644 --- a/src/templates/jobs/modules/list.html +++ b/src/templates/jobs/modules/list.html @@ -90,6 +90,13 @@ {% end %} + + {# Log #} + {% if job.is_running() %} +
    + {% module JobsLogStream(job, limit=5) %} +
    + {% end %} {% end %} diff --git a/src/templates/jobs/modules/log-stream.html b/src/templates/jobs/modules/log-stream.html index b2269c99..36237426 100644 --- a/src/templates/jobs/modules/log-stream.html +++ b/src/templates/jobs/modules/log-stream.html @@ -1 +1,2 @@ -
    + diff --git a/src/web/jobs.py b/src/web/jobs.py index f15621eb..ba317e8c 100644 --- a/src/web/jobs.py +++ b/src/web/jobs.py @@ -235,8 +235,8 @@ class ListModule(ui_modules.UIModule): class LogStreamModule(ui_modules.UIModule): - def render(self, job): - return self.render_string("jobs/modules/log-stream.html", job=job) + def render(self, job, limit=None): + return self.render_string("jobs/modules/log-stream.html", job=job, limit=limit) def javascript_files(self): return [