Skip to content

Commit

Permalink
Merge pull request #92 from Hannes221/91-colored-tracebacks
Browse files Browse the repository at this point in the history
Feat: Colored traceback
  • Loading branch information
Hannes221 authored Aug 6, 2024
2 parents f36fac4 + 2791ef7 commit a26a106
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 75 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <hannespfau@gmail.com>"]
readme = "README.md"
Expand All @@ -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]
Expand Down
16 changes: 15 additions & 1 deletion rq_dashboard_fast/rq_dashboard_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
149 changes: 76 additions & 73 deletions rq_dashboard_fast/templates/job.html
Original file line number Diff line number Diff line change
@@ -1,82 +1,85 @@
{% extends "base.html" %} {% block content %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Job Details</title>
<style>
.back-button-container {
display: flex;
justify-content: center;
margin-top: 10px;
}

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Job Details</title>
<style>
.back-button-container {
display: flex;
justify-content: center;
margin-top: 10px;
}
.back-button {
padding: 10px 15px;
color: #ececec;
border: 2px solid #000000;
border-radius: 5px;
text-decoration: none;
background-color: #000000;
transition: background-color 0.3s ease, color 0.3s ease,
border-color 0.3s ease;
cursor: pointer;
}

.back-button {
padding: 10px 15px;
color: #ececec;
border: 2px solid #000000;
border-radius: 5px;
text-decoration: none;
background-color: #000000;
transition: background-color 0.3s ease, color 0.3s ease,
border-color 0.3s ease;
cursor: pointer;
}
.back-button:hover {
background-color: #534c4c;
color: #ececec;
border-color: #534c4c;
}

.back-button:hover {
background-color: #534c4c;
color: #ececec;
border-color: #534c4c;
}
</style>
</head>
{{ css|safe }}
</style>
</head>

<body>
<div class="h2-section">
<h2>Job Details</h2>
</div>
<div class="section">
<table id="jobs">
<tr>
<th>ID</th>
<td class="table-cell">{{ job_data.id }}</td>
</tr>
<tr>
<th>Name</th>
<td class="table-cell">{{ job_data.name }}</td>
</tr>
<tr>
<th>Created At</th>
<td class="table-cell">{{ job_data.created_at }}</td>
</tr>
<tr>
<th>Enqueued At</th>
<td class="table-cell">{{ job_data.enqueued_at }}</td>
</tr>
<tr>
<th>Ended At</th>
<td class="table-cell">{{ job_data.ended_at }}</td>
</tr>
<tr>
<th>Result</th>
<td class="table-cell">{{ job_data.result }}</td>
</tr>
<tr>
<th>Exception Info</th>
<td class="table-cell">{{ job_data.exc_info }}</td>
</tr>
<tr>
<th>Meta</th>
<td class="table-cell">{{ job_data.meta }}</td>
</tr>
</table>
<div class="back-button-container">
<a href="javascript:history.back()" class="back-button">Back</a>
<body>
<div class="h2-section">
<h2>Job Details</h2>
</div>
</div>
</body>

<div class="section">
<table id="jobs">
<tr>
<th>ID</th>
<td class="table-cell">{{ job_data.id }}</td>
</tr>
<tr>
<th>Name</th>
<td class="table-cell">{{ job_data.name }}</td>
</tr>
<tr>
<th>Created At</th>
<td class="table-cell">{{ job_data.created_at }}</td>
</tr>
<tr>
<th>Enqueued At</th>
<td class="table-cell">{{ job_data.enqueued_at }}</td>
</tr>
<tr>
<th>Ended At</th>
<td class="table-cell">{{ job_data.ended_at }}</td>
</tr>
<tr>
<th>Result</th>
<td class="table-cell"><pre>{{ job_data.result }}</pre></td>
</tr>
<tr>
<th>Exception Info</th>
<td class="table-cell">
{% if col_exc_info %}{{ col_exc_info|safe }}{% else %}
<pre>{{ job_data.exc_info }}{% endif %}</pre>
</td>
</tr>
<tr>
<th>Meta</th>
<td class="table-cell"><pre>{{ job_data.meta }}</pre></td>
</tr>
</table>
<div class="back-button-container">
<a href="javascript:history.back()" class="back-button">Back</a>
</div>
</div>
</body>
</html>
{% endblock %}
{% endblock %}

0 comments on commit a26a106

Please sign in to comment.