From 2791ef7aa9fee5d33228319f6d0b10eece2ccd2f Mon Sep 17 00:00:00 2001 From: Hannes221 Date: Tue, 6 Aug 2024 17:23:12 +0200 Subject: [PATCH] Feat: Colored traceback --- pyproject.toml | 3 +- rq_dashboard_fast/rq_dashboard_fast.py | 16 ++- rq_dashboard_fast/templates/job.html | 149 +++++++++++++------------ 3 files changed, 93 insertions(+), 75 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c5c5995..a3461a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rq-dashboard-fast" -version = "0.5.5" +version = "0.5.6" description = "rq-dashboard-fast is a FastAPI-based dashboard to monitor your Redis-Queue (RQ) Jobs, Queues, and Workers" authors = ["Hannes221 "] readme = "README.md" @@ -17,6 +17,7 @@ jinja2 = ">=3.1.3" rq-scheduler = ">=0.13.1" pandas = ">=2.2.2" uvicorn = ">=0.30" +pygments = "^2.18.0" [tool.poetry.group.dev.dependencies] diff --git a/rq_dashboard_fast/rq_dashboard_fast.py b/rq_dashboard_fast/rq_dashboard_fast.py index ff39011..d45fa69 100644 --- a/rq_dashboard_fast/rq_dashboard_fast.py +++ b/rq_dashboard_fast/rq_dashboard_fast.py @@ -6,6 +6,9 @@ from fastapi import FastAPI, HTTPException, Query, Request from fastapi.responses import HTMLResponse, StreamingResponse from fastapi.templating import Jinja2Templates +from pygments import highlight +from pygments.formatters import HtmlFormatter +from pygments.lexers.python import Python2TracebackLexer from starlette.staticfiles import StaticFiles from rq_dashboard_fast.utils.jobs import ( @@ -53,7 +56,7 @@ def __init__( self.redis_url = redis_url self.protocol = protocol - self.rq_dashboard_version = "0.5.5" + self.rq_dashboard_version = "0.5.6" logger = logging.getLogger(__name__) @@ -225,6 +228,15 @@ async def get_job_data(job_id: str, request: Request): try: job = get_job(self.redis_url, job_id) + if job.exc_info: + css = HtmlFormatter().get_style_defs() + col_exc_info = highlight( + job.exc_info, Python2TracebackLexer(), HtmlFormatter() + ) + else: + css = None + col_exc_info = None + active_tab = "job" protocol = self.protocol if self.protocol else request.url.scheme @@ -235,6 +247,8 @@ async def get_job_data(job_id: str, request: Request): "request": request, "job_data": job, "active_tab": active_tab, + "css": css, + "col_exc_info": col_exc_info, "prefix": prefix, "rq_dashboard_version": self.rq_dashboard_version, "protocol": protocol, diff --git a/rq_dashboard_fast/templates/job.html b/rq_dashboard_fast/templates/job.html index b2237c2..4a2f291 100644 --- a/rq_dashboard_fast/templates/job.html +++ b/rq_dashboard_fast/templates/job.html @@ -1,82 +1,85 @@ {% extends "base.html" %} {% block content %} + + + + Job Details + - + {{ css|safe }} + + - -
-

Job Details

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ID{{ job_data.id }}
Name{{ job_data.name }}
Created At{{ job_data.created_at }}
Enqueued At{{ job_data.enqueued_at }}
Ended At{{ job_data.ended_at }}
Result{{ job_data.result }}
Exception Info{{ job_data.exc_info }}
Meta{{ job_data.meta }}
-
- Back + +
+

Job Details

-
- - +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID{{ job_data.id }}
Name{{ job_data.name }}
Created At{{ job_data.created_at }}
Enqueued At{{ job_data.enqueued_at }}
Ended At{{ job_data.ended_at }}
Result
{{ job_data.result }}
Exception Info + {% if col_exc_info %}{{ col_exc_info|safe }}{% else %} +
{{ job_data.exc_info }}{% endif %}
+
Meta
{{ job_data.meta }}
+
+ Back +
+
+ -{% endblock %} \ No newline at end of file +{% endblock %}