-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
42 lines (35 loc) · 1.29 KB
/
dashboard.py
File metadata and controls
42 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from flask import Flask, render_template
from htmx_flask import Htmx
from queue_system import storage
# --- App Setup ---
app = Flask(__name__)
htmx = Htmx(app)
# --- Main Page Route ---
@app.route('/')
def index():
"""Renders the main dashboard page."""
return render_template('index.html')
# --- API Routes (called by HTMX) ---
@app.route('/api/stats')
def stats():
"""Returns an HTML fragment with the latest stats."""
summary = storage.get_job_summary()
# Convert list of dicts to a simple dict
stats = {s['state']: s['count'] for s in summary}
return render_template('_stats.html', stats=stats)
@app.route('/api/jobs/<state>')
def jobs(state):
"""Returns an HTML fragment with the list of jobs for a given state."""
# Add a 'processing' state for the dashboard
if state == 'processing':
jobs_list = storage.get_jobs_by_state('processing')
elif state == 'completed':
jobs_list = storage.get_jobs_by_state('completed')
elif state == 'dead':
jobs_list = storage.get_jobs_by_state('dead')
else: # Default to 'pending'
state = 'pending'
jobs_list = storage.get_jobs_by_state('pending')
return render_template('_jobs.html', jobs=jobs_list, state=state)
if __name__ == "__main__":
app.run(debug=True, port=5000)