-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
212 lines (196 loc) · 8.38 KB
/
Copy pathindex.html
File metadata and controls
212 lines (196 loc) · 8.38 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mininq dashboard</title>
<link rel="stylesheet" href="/static/style.css">
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
</head>
<body>
<div class="header">
<h1>mininq</h1>
<span class="version" id="version-info">loading...</span>
</div>
<div class="stats-grid" id="stats-grid"></div>
<div class="section">
<h2>Queues</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>Concurrency</th>
<th>Pending</th>
<th>Running</th>
<th>Completed</th>
<th>Dead</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="queues-body"></tbody>
</table>
</div>
<div class="section">
<h2>Jobs</h2>
<div class="filters">
<select id="filter-status" onchange="refreshJobs()">
<option value="">All statuses</option>
<option value="pending">Pending</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
<option value="dead">Dead</option>
</select>
<select id="filter-queue" onchange="refreshJobs()">
<option value="">All queues</option>
</select>
</div>
<table>
<thead>
<tr>
<th>ID</th>
<th>Queue</th>
<th>Status</th>
<th>Priority</th>
<th>Attempt</th>
<th>Callback</th>
<th>Created</th>
</tr>
</thead>
<tbody id="jobs-body"></tbody>
</table>
</div>
<div class="section">
<h2>Schedules</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Queue</th>
<th>Cron</th>
<th>Callback</th>
<th>Enabled</th>
<th>Last Run</th>
<th>Next Run</th>
</tr>
</thead>
<tbody id="schedules-body"></tbody>
</table>
</div>
<script>
function formatUptime(secs) {
const d = Math.floor(secs / 86400);
const h = Math.floor((secs % 86400) / 3600);
const m = Math.floor((secs % 3600) / 60);
if (d > 0) return d + 'd ' + h + 'h';
if (h > 0) return h + 'h ' + m + 'm';
return m + 'm ' + (secs % 60) + 's';
}
function statusBadge(status) {
return '<span class="badge badge-' + status + '">' + status + '</span>';
}
function shortId(id) {
return '<span class="mono" title="' + id + '">' + id.substring(0, 8) + '</span>';
}
function shortTime(t) {
if (!t) return '-';
return t.replace('T', ' ').substring(0, 19);
}
async function fetchJSON(url) {
const r = await fetch(url);
return r.json();
}
async function refreshMetrics() {
try {
const m = await fetchJSON('/metrics');
document.getElementById('version-info').textContent = 'v' + m.version + ' | up ' + formatUptime(m.uptime_secs);
document.getElementById('stats-grid').innerHTML =
'<div class="stat-card"><span class="value">' + m.jobs.total + '</span><span class="label">Total Jobs</span></div>' +
'<div class="stat-card"><span class="value" style="color:var(--accent-yellow)">' + m.jobs.pending + '</span><span class="label">Pending</span></div>' +
'<div class="stat-card"><span class="value" style="color:var(--accent-blue)">' + m.jobs.running + '</span><span class="label">Running</span></div>' +
'<div class="stat-card"><span class="value" style="color:var(--accent-green)">' + m.jobs.completed + '</span><span class="label">Completed</span></div>' +
'<div class="stat-card"><span class="value" style="color:var(--accent)">' + m.jobs.dead + '</span><span class="label">Dead</span></div>' +
'<div class="stat-card"><span class="value">' + m.queues.length + '</span><span class="label">Queues</span></div>' +
'<div class="stat-card"><span class="value">' + m.schedules.enabled + '/' + m.schedules.total + '</span><span class="label">Schedules</span></div>';
} catch(e) { console.error('metrics error:', e); }
}
async function refreshQueues() {
try {
const queues = await fetchJSON('/queues');
const sel = document.getElementById('filter-queue');
const cur = sel.value;
sel.innerHTML = '<option value="">All queues</option>';
queues.forEach(q => {
sel.innerHTML += '<option value="' + q.name + '"' + (q.name === cur ? ' selected' : '') + '>' + q.name + '</option>';
});
document.getElementById('queues-body').innerHTML = queues.map(q =>
'<tr>' +
'<td class="mono">' + q.name + '</td>' +
'<td>' + (q.paused ? '<span class="badge badge-paused">paused</span>' : '<span class="badge badge-active">active</span>') + '</td>' +
'<td>' + q.max_concurrency + '</td>' +
'<td>' + q.pending + '</td>' +
'<td>' + q.running + '</td>' +
'<td>' + q.completed + '</td>' +
'<td>' + q.dead + '</td>' +
'<td>' + (q.paused
? '<button onclick="queueAction(\'' + q.name + '\',\'resume\')">Resume</button>'
: '<button onclick="queueAction(\'' + q.name + '\',\'pause\')">Pause</button>') +
'</td></tr>'
).join('');
} catch(e) { console.error('queues error:', e); }
}
async function refreshJobs() {
try {
let url = '/jobs?limit=50';
const status = document.getElementById('filter-status').value;
const queue = document.getElementById('filter-queue').value;
if (status) url += '&status=' + status;
if (queue) url += '&queue=' + queue;
const jobs = await fetchJSON(url);
document.getElementById('jobs-body').innerHTML = jobs.map(j =>
'<tr>' +
'<td>' + shortId(j.id) + '</td>' +
'<td class="mono">' + j.queue_name + '</td>' +
'<td>' + statusBadge(j.status) + '</td>' +
'<td>' + j.priority + '</td>' +
'<td>' + j.attempt + '/' + j.max_retries + '</td>' +
'<td class="truncate" title="' + j.callback_url + '">' + j.callback_url + '</td>' +
'<td>' + shortTime(j.created_at) + '</td>' +
'</tr>'
).join('');
} catch(e) { console.error('jobs error:', e); }
}
async function refreshSchedules() {
try {
const schedules = await fetchJSON('/schedules');
document.getElementById('schedules-body').innerHTML = schedules.map(s =>
'<tr>' +
'<td>' + shortId(s.id) + '</td>' +
'<td class="mono">' + s.queue_name + '</td>' +
'<td class="mono">' + s.cron_expression + '</td>' +
'<td class="truncate" title="' + s.callback_url + '">' + s.callback_url + '</td>' +
'<td>' + (s.enabled ? '<span class="badge badge-active">yes</span>' : '<span class="badge badge-paused">no</span>') + '</td>' +
'<td>' + shortTime(s.last_run_at) + '</td>' +
'<td>' + shortTime(s.next_run_at) + '</td>' +
'</tr>'
).join('');
} catch(e) { console.error('schedules error:', e); }
}
async function queueAction(name, action) {
await fetch('/queues/' + encodeURIComponent(name) + '/' + action, { method: 'POST' });
refreshQueues();
refreshMetrics();
}
// Initial load
refreshMetrics();
refreshQueues();
refreshJobs();
refreshSchedules();
// Polling
setInterval(refreshMetrics, 10000);
setInterval(refreshQueues, 5000);
setInterval(refreshJobs, 5000);
setInterval(refreshSchedules, 15000);
</script>
</body>
</html>