From: Michael Tremer Date: Thu, 6 Feb 2025 23:07:56 +0000 (+0000) Subject: jobs: Move log stream frontend code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=202578d672da6a8ff56430df038562ccb323ca69;p=pbs.git jobs: Move log stream frontend code Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 28d45da0..8a584848 100644 --- a/Makefile.am +++ b/Makefile.am @@ -255,11 +255,6 @@ dist_templates_jobs_messages_DATA = \ templates_jobs_messagesdir = $(templates_jobsdir)/messages -dist_templates_jobs_modules_DATA = \ - src/templates/jobs/modules/log-stream.html - -templates_jobs_modulesdir = $(templates_jobsdir)/modules - templates_messagesdir = $(templatesdir)/messages dist_templates_mirrors_DATA = \ @@ -345,14 +340,12 @@ CLEANFILES += \ static_js_DATA = \ src/static/js/jquery.min.js \ - src/static/js/job-log-stream.min.js \ src/static/js/notification-worker.min.js \ src/static/js/pbs.min.js static_jsdir = $(staticdir)/js EXTRA_DIST += \ - src/static/js/job-log-stream.js \ src/static/js/notification-worker.js \ src/static/js/pbs.js diff --git a/src/static/js/job-log-stream.js b/src/static/js/job-log-stream.js deleted file mode 100644 index 94a20f8a..00000000 --- a/src/static/js/job-log-stream.js +++ /dev/null @@ -1,43 +0,0 @@ -$(".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); - - // Make the URL - 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); - - stream.addEventListener("message", (event) => { - // Parse message as JSON - const data = JSON.parse(event.data); - - 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 = $("
  • "); - - // Set the log level - line.addClass(data.level); - - // Set the content - line.text(data.message); - - // Append it to the log window - log.append(line); - }); -}); diff --git a/src/static/js/pbs.js b/src/static/js/pbs.js index e4603c81..a1f979f0 100644 --- a/src/static/js/pbs.js +++ b/src/static/js/pbs.js @@ -191,3 +191,50 @@ $(".builders-stats").each(function() { updateProgressBar(swap_usage, data.swap_usage); }); }); + +/* + * Log Stream + */ +$(".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); + + // Make the URL + 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); + + stream.addEventListener("message", (event) => { + // Parse message as JSON + const data = JSON.parse(event.data); + + 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 = $("
  • "); + + // Set the log level + line.addClass(data.level); + + // Set the content + line.text(data.message); + + // Append it to the log window + log.append(line); + }); +}); diff --git a/src/templates/jobs/log-stream.html b/src/templates/jobs/log-stream.html index 2f133ba3..c9820d92 100644 --- a/src/templates/jobs/log-stream.html +++ b/src/templates/jobs/log-stream.html @@ -1,6 +1,6 @@ -{% extends "../base.html" %} +{% extends "base.html" %} -{% block title %}{{ job }} - {{ _("Log") }}{% end block %} +{% block title %}{{ job }} - {{ _("Log") }}{% endblock %} {% block container %} - {% module JobsLogStream(job) %} -{% end block %} + {{ JobLogStream(job) }} +{% endblock %} diff --git a/src/templates/jobs/macros.html b/src/templates/jobs/macros.html index 840a0714..8e897497 100644 --- a/src/templates/jobs/macros.html +++ b/src/templates/jobs/macros.html @@ -77,7 +77,7 @@ {# Log #} {% if job.is_running() %}
    - {..% module JobsLogStream(job, limit=5) %..} + {{ JobLogStream(job, limit=5) }}
    {# Dependency Issues #} @@ -226,3 +226,8 @@ {% endfor %} {% endmacro %} + +{% macro JobLogStream(job, small=False, limit=None) %} + +{% endmacro %} diff --git a/src/templates/jobs/modules/log-stream.html b/src/templates/jobs/modules/log-stream.html deleted file mode 100644 index 6cb93f6a..00000000 --- a/src/templates/jobs/modules/log-stream.html +++ /dev/null @@ -1,2 +0,0 @@ -