From: Michael Tremer Date: Wed, 19 Oct 2022 15:14:22 +0000 (+0000) Subject: jobs: Add log handler to stream the log to the browser X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c7b3d17593ae00c141e2d2312ae6a76393c6e18;p=pbs.git jobs: Add log handler to stream the log to the browser Signed-off-by: Michael Tremer --- diff --git a/src/templates/modules/jobs/list.html b/src/templates/modules/jobs/list.html index ba352b52..4a3c9c2d 100644 --- a/src/templates/modules/jobs/list.html +++ b/src/templates/modules/jobs/list.html @@ -64,6 +64,15 @@ {% end %} + + {# Footer with some useful buttons #} + {% end %} diff --git a/src/web/__init__.py b/src/web/__init__.py index c112b68d..fe195ff5 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -142,6 +142,7 @@ class Application(tornado.web.Application): (r"/queue", jobs.QueueHandler), # Jobs + (r"/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/log", jobs.LogHandler), (r"/job/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/abort", jobs.JobAbortHandler), (r"/job/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/buildroot", jobs.JobBuildrootHandler), diff --git a/src/web/jobs.py b/src/web/jobs.py index 4b412057..ba96ef2f 100644 --- a/src/web/jobs.py +++ b/src/web/jobs.py @@ -9,6 +9,30 @@ class QueueHandler(base.BaseHandler): self.render("queue.html", queue=self.backend.jobqueue) +class LogHandler(base.BaseHandler): + async def get(self, uuid): + job = self.backend.jobs.get_by_uuid(uuid) + if not job: + raise tornado.web.HTTPError("Could not find job %s" % uuid) + + tail = self.get_argument_int("tail", None) + + # Should we tail the log, or stream the entire file? + try: + log = await job.tail_log(tail) if tail else await job.open_log() + + # Send 404 if there is no log file + except FileNotFoundError as e: + raise tornado.web.HTTPError(404, "Could not find log for %s" % job) from e + + # Set Content-Type header + self.set_header("Content-Type", "text/plain") + + # Stream the entire log + for line in log: + self.write(line) + + class JobBuildrootHandler(base.BaseHandler): def get(self, uuid): job = self.backend.jobs.get_by_uuid(uuid)