|
1 | 1 | <script server> |
2 | | -import { getQueueManager } from '@stacksjs/queue/bun-queue' |
3 | | -import { checkQueueHealth } from '@stacksjs/queue' |
| 2 | +const BQ_API = 'http://localhost:4400' |
4 | 3 |
|
5 | 4 | let queues = [] |
6 | 5 | let stats = { totalQueues: 0, totalJobs: 0, activeJobs: 0, completedJobs: 0, failedJobs: 0, throughputPerMinute: 0 } |
7 | | -let healthStatus = null |
8 | 6 |
|
9 | 7 | try { |
10 | | - const manager = getQueueManager() |
11 | | - if (manager) { |
12 | | - for (const connName of manager.getConnections()) { |
13 | | - try { |
14 | | - const conn = manager.connection(connName) |
15 | | - for (const q of conn.queues.values()) { |
16 | | - const counts = await q.getJobCounts() |
17 | | - const isPaused = typeof q.isPaused === 'function' ? await q.isPaused() : false |
18 | | - queues.push({ |
19 | | - name: q.name, |
20 | | - status: isPaused ? 'paused' : counts.active > 0 ? 'active' : counts.waiting > 0 ? 'active' : 'idle', |
21 | | - pending: counts.waiting || 0, |
22 | | - active: counts.active || 0, |
23 | | - completed: counts.completed || 0, |
24 | | - failed: counts.failed || 0, |
25 | | - total: (counts.waiting || 0) + (counts.active || 0) + (counts.completed || 0) + (counts.failed || 0), |
26 | | - }) |
27 | | - stats.totalQueues++ |
28 | | - stats.totalJobs += (counts.waiting || 0) + (counts.active || 0) + (counts.completed || 0) + (counts.failed || 0) |
29 | | - stats.activeJobs += counts.active || 0 |
30 | | - stats.completedJobs += counts.completed || 0 |
31 | | - stats.failedJobs += counts.failed || 0 |
32 | | - } |
33 | | - } catch {} |
34 | | - } |
| 8 | + const [queuesRes, statsRes] = await Promise.all([ |
| 9 | + fetch(`${BQ_API}/api/queues`), |
| 10 | + fetch(`${BQ_API}/api/stats`), |
| 11 | + ]) |
| 12 | + |
| 13 | + if (queuesRes.ok) { |
| 14 | + const data = await queuesRes.json() |
| 15 | + queues = data.map(function(q) { |
| 16 | + return { |
| 17 | + name: q.name, |
| 18 | + status: q.status || 'idle', |
| 19 | + pending: q.pendingJobs || 0, |
| 20 | + active: q.activeJobs || 0, |
| 21 | + completed: q.completedJobs || 0, |
| 22 | + failed: q.failedJobs || 0, |
| 23 | + total: q.jobCount || 0, |
| 24 | + } |
| 25 | + }) |
| 26 | + } |
| 27 | + |
| 28 | + if (statsRes.ok) { |
| 29 | + stats = await statsRes.json() |
35 | 30 | } |
36 | 31 | } catch { |
37 | | - // Queue system not initialized — show empty state |
| 32 | + // bun-queue devtools not running — show empty state |
38 | 33 | } |
39 | 34 |
|
40 | | -try { |
41 | | - healthStatus = await checkQueueHealth() |
42 | | -} catch {} |
43 | | - |
44 | 35 | function statusClass(s) { |
45 | 36 | if (!s) return 'bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300' |
46 | 37 | s = String(s).toLowerCase() |
@@ -117,23 +108,4 @@ function statusClass(s) { |
117 | 108 | </div> |
118 | 109 | @endif |
119 | 110 |
|
120 | | - <!-- Health Status --> |
121 | | - @if (healthStatus) |
122 | | - <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 p-5"> |
123 | | - <div class="flex items-center justify-between mb-4"> |
124 | | - <span class="font-semibold text-gray-900 dark:text-white">Queue Health</span> |
125 | | - <span class="px-2.5 py-1 text-xs font-semibold rounded-full {{ statusClass(healthStatus.status || 'unknown') }}">{{ healthStatus.status || 'unknown' }}</span> |
126 | | - </div> |
127 | | - @if (healthStatus.queues) |
128 | | - <div class="divide-y divide-gray-100 dark:divide-gray-700"> |
129 | | - @foreach (healthStatus.queues as qh) |
130 | | - <div class="flex items-center justify-between py-3"> |
131 | | - <span class="text-sm text-gray-900 dark:text-white">{{ qh.name }}</span> |
132 | | - <span class="px-2.5 py-1 text-xs font-semibold rounded-full {{ statusClass(qh.status) }}">{{ qh.status }}</span> |
133 | | - </div> |
134 | | - @endforeach |
135 | | - </div> |
136 | | - @endif |
137 | | - </div> |
138 | | - @endif |
139 | 111 | </div> |
0 commit comments