]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Add log handler to stream the log to the browser
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 15:14:22 +0000 (15:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 15:14:22 +0000 (15:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/templates/modules/jobs/list.html
src/web/__init__.py
src/web/jobs.py

index ba352b523bee49a7803afd7f5a23092f0c1e1899..4a3c9c2d490bb7be7cafa817eb940259cbbb9baf 100644 (file)
                                        </ul>
                                </div>
                        {% end %}
+
+                       {# Footer with some useful buttons #}
+                       <footer class="card-footer">
+                               {% if job.has_log() %}
+                                       <a href="/jobs/{{ job.uuid }}/log" class="card-footer-item">
+                                               {{ _("Download Log") }}
+                                       </a>
+                               {% end %}
+                       </footer>
                </div>
        </div>
 {% end %}
index c112b68dc1a1d676226d6911fb48800c7433d312..fe195ff52839a85e9295c2591605583f542488ca 100644 (file)
@@ -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),
 
index 4b41205720b517818356145045f16005184655e5..ba96ef2fc2d96d09aa9e130765e98d7810ba401b 100644 (file)
@@ -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)