@checkstack/queue-frontend 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +133 -0
- package/package.json +9 -9
- package/src/components/QueueInfrastructureTab.tsx +21 -0
- package/src/components/QueueRuntimePanel.tsx +328 -0
- package/src/index.tsx +20 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,138 @@
|
|
|
1
1
|
# @checkstack/queue-frontend
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- aa89bc5: Replace the bespoke `registerInfrastructureTab()` registry with a standard
|
|
8
|
+
slot-extension contract (`InfrastructureTabsSlot` from
|
|
9
|
+
`@checkstack/infrastructure-common`). Plugins now contribute infrastructure
|
|
10
|
+
tabs via `createSlotExtension`, depending only on the slot owner.
|
|
11
|
+
|
|
12
|
+
The slot system in `@checkstack/frontend-api` gains a second type parameter
|
|
13
|
+
on `createSlot<TContext, TMetadata>` so extensions can declare typed static
|
|
14
|
+
metadata at registration time (label, icon, access rules, ordering for the
|
|
15
|
+
infrastructure tab bar). A new `useSlotExtensions(slot)` hook returns typed
|
|
16
|
+
extensions and subscribes to plugin lifecycle changes.
|
|
17
|
+
|
|
18
|
+
Each tab body now stacks a **Runtime** sub-section (live state, read-only)
|
|
19
|
+
on top of a **Configuration** sub-section (settings, gated by `canUpdate`).
|
|
20
|
+
|
|
21
|
+
**Queue runtime panel.** Surfaces aggregated counts (pending / processing /
|
|
22
|
+
completed / failed) plus three sub-tabs of recent jobs: **Active**, **Recent
|
|
23
|
+
failed** (with the failure message), and **Recent completed** (with
|
|
24
|
+
duration). Job payloads are deliberately not surfaced — they may carry
|
|
25
|
+
secrets and need a separate manage-access gate to be shown.
|
|
26
|
+
|
|
27
|
+
To support this, `Queue<T>` gains a required `listJobs(opts)` method
|
|
28
|
+
returning `JobSummary[]` (no payloads), and `QueueStats` gains a
|
|
29
|
+
`scope: "instance" | "cluster"` field. The in-memory queue keeps rolling
|
|
30
|
+
ring buffers (200 entries) for completed/failed history and tracks active
|
|
31
|
+
jobs by id; BullMQ uses native `getJobs`. `QueueManager.listJobs` aggregates
|
|
32
|
+
across queues and sorts (most-recent-first for terminal states, FIFO for
|
|
33
|
+
active/waiting/delayed).
|
|
34
|
+
|
|
35
|
+
**Cache runtime panel.** Lists the top N entries by size (or by recency) so
|
|
36
|
+
operators can debug a cache filling up. Values are deliberately omitted —
|
|
37
|
+
PII / secret risk. Backends opt in via an optional `listEntries?` method on
|
|
38
|
+
`CacheProvider`; non-supporting backends return `{ supported: false }` and
|
|
39
|
+
the UI renders a "not supported by this backend" hint. The in-memory cache
|
|
40
|
+
implements it using its existing per-entry byte tracking.
|
|
41
|
+
|
|
42
|
+
`CacheStats` also gains `scope: "instance" | "cluster"`.
|
|
43
|
+
|
|
44
|
+
**Multi-instance scope warning.** A new `<InstanceScopeBanner>` component in
|
|
45
|
+
`@checkstack/ui` renders a yellow banner above any runtime panel whose
|
|
46
|
+
backend reports `scope: "instance"` — i.e. in-memory queue or cache running
|
|
47
|
+
in a horizontally scaled deployment. The banner explains the metrics are
|
|
48
|
+
local to the responding replica and recommends switching to a clustered
|
|
49
|
+
backend (Redis-backed queue / cache) for cluster-wide visibility.
|
|
50
|
+
|
|
51
|
+
**Bug fix — stable cache provider proxy.** `CacheManagerImpl.getProvider()`
|
|
52
|
+
now returns a single stable proxy that delegates to whatever provider is
|
|
53
|
+
currently active. Previously, consumers of `createCachedScope` (and any
|
|
54
|
+
direct `cacheManager.getProvider()` caller) captured the active provider
|
|
55
|
+
reference at plugin-init time. After any `setActiveBackend` call — including
|
|
56
|
+
saving the same memory config in the new Cache tab, which reconstructs the
|
|
57
|
+
in-memory cache — those scopes wrote to an orphaned old provider while the
|
|
58
|
+
runtime panel read stats from the new (empty) one, making the runtime panel
|
|
59
|
+
appear to report 0 keys. With the proxy, all consumers share a single stable
|
|
60
|
+
identity and writes always land in the active provider.
|
|
61
|
+
|
|
62
|
+
**Bytes tracking on the in-memory cache.** `InMemoryCache.getStats().sizeBytes`
|
|
63
|
+
now returns a running approximation (UTF-8 bytes of the key plus
|
|
64
|
+
`v8.serialize(value).byteLength`, with a JSON fallback) that's kept in sync
|
|
65
|
+
across all eviction paths. Treat the number as a sanity gauge; it doesn't
|
|
66
|
+
include `Map` per-entry overhead.
|
|
67
|
+
|
|
68
|
+
**Pagination.** Both `Queue<T>.listJobs` and `CacheProvider.listEntries?`
|
|
69
|
+
are offset-paginated. Inputs gain an `offset: number`; outputs change to
|
|
70
|
+
`{ items, total: number | null, hasMore: boolean }`. `total` is nullable
|
|
71
|
+
so backends that can't compute it cheaply still paginate via `hasMore`.
|
|
72
|
+
The UI uses the existing `<Pagination>` component with a 25-row default
|
|
73
|
+
page size. `QueueManager.listJobs` aggregates by over-fetching
|
|
74
|
+
`[0, offset+limit)` per queue, merge-sorting, then slicing the window —
|
|
75
|
+
optimal for the single-queue case, acceptable for the multi-queue case
|
|
76
|
+
within the UI's reasonable page-depth bounds. BullMQ uses native offset
|
|
77
|
+
ranges via `getJobs(types, start, end)` plus `getJobCounts` for `total`.
|
|
78
|
+
|
|
79
|
+
**Pending tab.** The Queue runtime panel exposes a virtual `"pending"`
|
|
80
|
+
state (waiting ∪ delayed, FIFO). It's now the default sub-tab, since
|
|
81
|
+
"what's queued up?" is the most common question. Per-row state is shown
|
|
82
|
+
when viewing the combined list.
|
|
83
|
+
|
|
84
|
+
**Recurring schedules visible under Pending.** Cron- and interval-based
|
|
85
|
+
recurring jobs (e.g. healthchecks) are surfaced under Pending/Delayed
|
|
86
|
+
between fires, with a `nextRunAt` countdown column and a "(recurring)"
|
|
87
|
+
label. `JobSummary` gains optional `nextRunAt: Date` and `recurring:
|
|
88
|
+
boolean` fields. The in-memory queue synthesises these rows from its
|
|
89
|
+
`recurringJobs` registry; BullMQ already materialises the next fire of
|
|
90
|
+
each scheduler as a delayed job and we now surface its trigger time and
|
|
91
|
+
the `repeatJobKey`-derived `recurring` flag.
|
|
92
|
+
|
|
93
|
+
**Bug fix — drop hook emits with no listeners.** `EventBus.emit` no
|
|
94
|
+
longer enqueues a job when zero listeners (distributed or instance-local)
|
|
95
|
+
are registered for the hook. Previously, hooks like
|
|
96
|
+
`core.plugin.initialized` — emitted on every plugin init but subscribed
|
|
97
|
+
to by nothing in the core repo — accumulated one waiting job per emit
|
|
98
|
+
forever. The in-memory queue's `processNext` short-circuits when there
|
|
99
|
+
are zero consumer groups, so its post-loop cleanup never ran for these
|
|
100
|
+
orphaned jobs. The fix drops the emit at the source and logs a debug
|
|
101
|
+
line. Note: in distributed deployments using a Redis-backed queue, this
|
|
102
|
+
means a subscriber on another replica won't receive an event if no
|
|
103
|
+
replica that emits it has a local listener. Plugins needing cross-process
|
|
104
|
+
delivery must register their listener on every replica that should
|
|
105
|
+
receive the hook.
|
|
106
|
+
|
|
107
|
+
**Breaking notes (treated as minor under beta semantics)**:
|
|
108
|
+
|
|
109
|
+
- `@checkstack/infrastructure-common` removes `registerInfrastructureTab`
|
|
110
|
+
and `getInfrastructureTabs`; former callers must register an extension
|
|
111
|
+
into `InfrastructureTabsSlot`.
|
|
112
|
+
- `@checkstack/queue-api`'s `Queue<T>` interface requires the new
|
|
113
|
+
`listJobs(opts)` method returning `ListJobsResult` (paginated). Both
|
|
114
|
+
bundled queue backends (memory, BullMQ) are updated; out-of-tree
|
|
115
|
+
implementations will need to add it.
|
|
116
|
+
- `QueueStats` and `CacheStats` add a required `scope` field.
|
|
117
|
+
- `CacheProvider.listEntries?` (when implemented) now returns
|
|
118
|
+
`ListEntriesResult` instead of `CacheEntrySummary[]`.
|
|
119
|
+
- `JobState` adds a `"pending"` variant.
|
|
120
|
+
|
|
121
|
+
### Patch Changes
|
|
122
|
+
|
|
123
|
+
- Updated dependencies [42abfff]
|
|
124
|
+
- Updated dependencies [3547670]
|
|
125
|
+
- Updated dependencies [1ef2e79]
|
|
126
|
+
- Updated dependencies [aa89bc5]
|
|
127
|
+
- Updated dependencies [950d6ec]
|
|
128
|
+
- Updated dependencies [3547670]
|
|
129
|
+
- @checkstack/common@0.9.0
|
|
130
|
+
- @checkstack/ui@1.8.0
|
|
131
|
+
- @checkstack/frontend-api@0.5.0
|
|
132
|
+
- @checkstack/infrastructure-common@0.3.0
|
|
133
|
+
- @checkstack/queue-common@0.4.0
|
|
134
|
+
- @checkstack/signal-frontend@0.1.2
|
|
135
|
+
|
|
3
136
|
## 0.3.3
|
|
4
137
|
|
|
5
138
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/queue-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"lint:code": "eslint . --max-warnings 0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@checkstack/common": "0.
|
|
25
|
-
"@checkstack/frontend-api": "0.4.
|
|
26
|
-
"@checkstack/infrastructure-common": "0.2.
|
|
27
|
-
"@checkstack/queue-common": "0.3.
|
|
28
|
-
"@checkstack/signal-frontend": "0.1.
|
|
29
|
-
"@checkstack/ui": "1.7.
|
|
24
|
+
"@checkstack/common": "0.8.0",
|
|
25
|
+
"@checkstack/frontend-api": "0.4.2",
|
|
26
|
+
"@checkstack/infrastructure-common": "0.2.3",
|
|
27
|
+
"@checkstack/queue-common": "0.3.1",
|
|
28
|
+
"@checkstack/signal-frontend": "0.1.1",
|
|
29
|
+
"@checkstack/ui": "1.7.1",
|
|
30
30
|
"ajv": "^8.18.0",
|
|
31
31
|
"ajv-formats": "^3.0.1",
|
|
32
32
|
"lucide-react": "^0.468.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/react": "^18.3.18",
|
|
39
39
|
"typescript": "^5.7.2",
|
|
40
|
-
"@checkstack/tsconfig": "0.0.
|
|
41
|
-
"@checkstack/scripts": "0.
|
|
40
|
+
"@checkstack/tsconfig": "0.0.7",
|
|
41
|
+
"@checkstack/scripts": "0.3.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { InfrastructureTabContext } from "@checkstack/infrastructure-common";
|
|
2
|
+
import { QueueConfigTab } from "./QueueConfigTab";
|
|
3
|
+
import { QueueRuntimePanel } from "./QueueRuntimePanel";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Queue tab body for the Infrastructure Settings page.
|
|
7
|
+
*
|
|
8
|
+
* Stacks two sub-sections inside the same tab:
|
|
9
|
+
* - Runtime: live job counts (read-only, always shown).
|
|
10
|
+
* - Configuration: provider selection + tuning (gated by `canUpdate`).
|
|
11
|
+
*/
|
|
12
|
+
export const QueueInfrastructureTab = ({
|
|
13
|
+
canUpdate,
|
|
14
|
+
}: InfrastructureTabContext) => {
|
|
15
|
+
return (
|
|
16
|
+
<div className="space-y-6">
|
|
17
|
+
<QueueRuntimePanel />
|
|
18
|
+
<QueueConfigTab canUpdate={canUpdate} />
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { usePluginClient } from "@checkstack/frontend-api";
|
|
3
|
+
import { QueueApi, type JobStateDto } from "@checkstack/queue-common";
|
|
4
|
+
import {
|
|
5
|
+
Card,
|
|
6
|
+
CardContent,
|
|
7
|
+
CardDescription,
|
|
8
|
+
CardHeader,
|
|
9
|
+
CardTitle,
|
|
10
|
+
InstanceScopeBanner,
|
|
11
|
+
Pagination,
|
|
12
|
+
Table,
|
|
13
|
+
TableBody,
|
|
14
|
+
TableCell,
|
|
15
|
+
TableHead,
|
|
16
|
+
TableHeader,
|
|
17
|
+
TableRow,
|
|
18
|
+
Tabs,
|
|
19
|
+
TabPanel,
|
|
20
|
+
} from "@checkstack/ui";
|
|
21
|
+
import {
|
|
22
|
+
Activity,
|
|
23
|
+
AlertTriangle,
|
|
24
|
+
CheckCircle2,
|
|
25
|
+
Clock,
|
|
26
|
+
Hourglass,
|
|
27
|
+
Loader2,
|
|
28
|
+
PlayCircle,
|
|
29
|
+
} from "lucide-react";
|
|
30
|
+
|
|
31
|
+
const REFRESH_INTERVAL_MS = 5000;
|
|
32
|
+
const PAGE_SIZE = 25;
|
|
33
|
+
|
|
34
|
+
const formatNumber = (n: number) =>
|
|
35
|
+
n.toLocaleString(undefined, { maximumFractionDigits: 0 });
|
|
36
|
+
|
|
37
|
+
const formatRelative = (date?: Date) => {
|
|
38
|
+
if (!date) return "—";
|
|
39
|
+
const ms = Date.now() - date.getTime();
|
|
40
|
+
const sec = Math.round(ms / 1000);
|
|
41
|
+
if (sec < 60) return `${sec}s ago`;
|
|
42
|
+
const min = Math.round(sec / 60);
|
|
43
|
+
if (min < 60) return `${min}m ago`;
|
|
44
|
+
const hr = Math.round(min / 60);
|
|
45
|
+
if (hr < 24) return `${hr}h ago`;
|
|
46
|
+
return `${Math.round(hr / 24)}d ago`;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const formatDuration = (start?: Date, end?: Date) => {
|
|
50
|
+
if (!start) return "—";
|
|
51
|
+
const finish = end ?? new Date();
|
|
52
|
+
const ms = finish.getTime() - start.getTime();
|
|
53
|
+
if (ms < 1000) return `${ms}ms`;
|
|
54
|
+
if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
|
|
55
|
+
return `${Math.round(ms / 60_000)}m`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const truncateMiddle = (s: string, head = 8, tail = 6) => {
|
|
59
|
+
if (s.length <= head + tail + 1) return s;
|
|
60
|
+
return `${s.slice(0, head)}…${s.slice(-tail)}`;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const formatCountdown = (target?: Date) => {
|
|
64
|
+
if (!target) return "—";
|
|
65
|
+
const ms = target.getTime() - Date.now();
|
|
66
|
+
if (ms <= 0) return "now";
|
|
67
|
+
const sec = Math.round(ms / 1000);
|
|
68
|
+
if (sec < 60) return `in ${sec}s`;
|
|
69
|
+
const min = Math.round(sec / 60);
|
|
70
|
+
if (min < 60) return `in ${min}m`;
|
|
71
|
+
const hr = Math.round(min / 60);
|
|
72
|
+
if (hr < 24) return `in ${hr}h`;
|
|
73
|
+
return `in ${Math.round(hr / 24)}d`;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
interface CountTileProps {
|
|
77
|
+
label: string;
|
|
78
|
+
value: number | undefined;
|
|
79
|
+
icon: React.ComponentType<{ className?: string }>;
|
|
80
|
+
tone: "default" | "warning" | "danger" | "success";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const toneClasses: Record<CountTileProps["tone"], string> = {
|
|
84
|
+
default: "text-muted-foreground",
|
|
85
|
+
warning: "text-amber-600 dark:text-amber-400",
|
|
86
|
+
danger: "text-destructive",
|
|
87
|
+
success: "text-emerald-600 dark:text-emerald-400",
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const CountTile = ({ label, value, icon: Icon, tone }: CountTileProps) => (
|
|
91
|
+
<div className="flex items-center gap-3 rounded-lg border bg-card px-4 py-3">
|
|
92
|
+
<Icon className={`h-5 w-5 shrink-0 ${toneClasses[tone]}`} />
|
|
93
|
+
<div className="min-w-0">
|
|
94
|
+
<div className="text-xs font-medium text-muted-foreground">{label}</div>
|
|
95
|
+
<div className="text-2xl font-semibold tabular-nums">
|
|
96
|
+
{value === undefined ? "—" : formatNumber(value)}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
interface JobsTableProps {
|
|
103
|
+
state: JobStateDto;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const JobsTable = ({ state }: JobsTableProps) => {
|
|
107
|
+
const queueClient = usePluginClient(QueueApi);
|
|
108
|
+
const [page, setPage] = useState(1);
|
|
109
|
+
const offset = (page - 1) * PAGE_SIZE;
|
|
110
|
+
|
|
111
|
+
const { data, isLoading, error } = queueClient.listJobs.useQuery(
|
|
112
|
+
{ state, offset, limit: PAGE_SIZE },
|
|
113
|
+
{ refetchInterval: REFRESH_INTERVAL_MS },
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (error) {
|
|
117
|
+
return <p className="text-sm text-destructive">Failed to load jobs.</p>;
|
|
118
|
+
}
|
|
119
|
+
if (isLoading) {
|
|
120
|
+
return <p className="text-sm text-muted-foreground">Loading…</p>;
|
|
121
|
+
}
|
|
122
|
+
if (!data || data.items.length === 0) {
|
|
123
|
+
return <p className="text-sm text-muted-foreground">No {state} jobs.</p>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const showFinished = state === "completed" || state === "failed";
|
|
127
|
+
const showError = state === "failed";
|
|
128
|
+
const showState = state === "pending";
|
|
129
|
+
const showNextRun =
|
|
130
|
+
state === "pending" || state === "delayed" || state === "waiting";
|
|
131
|
+
|
|
132
|
+
// total may be null for backends that can't compute it cheaply; in that
|
|
133
|
+
// case we synthesise totalPages from hasMore so the next button stays usable.
|
|
134
|
+
const totalPages =
|
|
135
|
+
data.total === null
|
|
136
|
+
? data.hasMore
|
|
137
|
+
? page + 1
|
|
138
|
+
: page
|
|
139
|
+
: Math.max(1, Math.ceil(data.total / PAGE_SIZE));
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div className="space-y-3">
|
|
143
|
+
<Table>
|
|
144
|
+
<TableHeader>
|
|
145
|
+
<TableRow>
|
|
146
|
+
<TableHead className="w-[140px]">Job ID</TableHead>
|
|
147
|
+
<TableHead>Queue</TableHead>
|
|
148
|
+
{showState && <TableHead>State</TableHead>}
|
|
149
|
+
<TableHead>Enqueued</TableHead>
|
|
150
|
+
{showNextRun && <TableHead>Next run</TableHead>}
|
|
151
|
+
{state === "active" && <TableHead>Running for</TableHead>}
|
|
152
|
+
{showFinished && <TableHead>Finished</TableHead>}
|
|
153
|
+
{showFinished && <TableHead>Duration</TableHead>}
|
|
154
|
+
<TableHead className="text-right">Attempts</TableHead>
|
|
155
|
+
{showError && <TableHead>Error</TableHead>}
|
|
156
|
+
</TableRow>
|
|
157
|
+
</TableHeader>
|
|
158
|
+
<TableBody>
|
|
159
|
+
{data.items.map((job) => (
|
|
160
|
+
<TableRow key={job.id}>
|
|
161
|
+
<TableCell
|
|
162
|
+
className="font-mono text-xs whitespace-nowrap"
|
|
163
|
+
title={job.id}
|
|
164
|
+
>
|
|
165
|
+
{truncateMiddle(job.id)}
|
|
166
|
+
</TableCell>
|
|
167
|
+
<TableCell>{job.name ?? "—"}</TableCell>
|
|
168
|
+
{showState && (
|
|
169
|
+
<TableCell className="capitalize">
|
|
170
|
+
{job.recurring ? "Recurring" : job.state}
|
|
171
|
+
</TableCell>
|
|
172
|
+
)}
|
|
173
|
+
<TableCell title={job.enqueuedAt.toString()}>
|
|
174
|
+
{formatRelative(job.enqueuedAt)}
|
|
175
|
+
</TableCell>
|
|
176
|
+
{showNextRun && (
|
|
177
|
+
<TableCell title={job.nextRunAt?.toString()}>
|
|
178
|
+
{formatCountdown(job.nextRunAt)}
|
|
179
|
+
</TableCell>
|
|
180
|
+
)}
|
|
181
|
+
{state === "active" && (
|
|
182
|
+
<TableCell>{formatDuration(job.startedAt)}</TableCell>
|
|
183
|
+
)}
|
|
184
|
+
{showFinished && (
|
|
185
|
+
<TableCell title={job.finishedAt?.toString()}>
|
|
186
|
+
{formatRelative(job.finishedAt)}
|
|
187
|
+
</TableCell>
|
|
188
|
+
)}
|
|
189
|
+
{showFinished && (
|
|
190
|
+
<TableCell>
|
|
191
|
+
{formatDuration(job.startedAt, job.finishedAt)}
|
|
192
|
+
</TableCell>
|
|
193
|
+
)}
|
|
194
|
+
<TableCell className="text-right tabular-nums">
|
|
195
|
+
{job.attempts}
|
|
196
|
+
</TableCell>
|
|
197
|
+
{showError && (
|
|
198
|
+
<TableCell
|
|
199
|
+
className="max-w-[280px] truncate text-destructive"
|
|
200
|
+
title={job.failedReason}
|
|
201
|
+
>
|
|
202
|
+
{job.failedReason ?? "—"}
|
|
203
|
+
</TableCell>
|
|
204
|
+
)}
|
|
205
|
+
</TableRow>
|
|
206
|
+
))}
|
|
207
|
+
</TableBody>
|
|
208
|
+
</Table>
|
|
209
|
+
<Pagination
|
|
210
|
+
page={page}
|
|
211
|
+
totalPages={totalPages}
|
|
212
|
+
onPageChange={setPage}
|
|
213
|
+
total={data.total ?? undefined}
|
|
214
|
+
showTotal={data.total !== null}
|
|
215
|
+
/>
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const SUB_TABS = [
|
|
221
|
+
{ id: "pending", label: "Pending", icon: <Hourglass className="h-4 w-4" /> },
|
|
222
|
+
{ id: "active", label: "Active", icon: <PlayCircle className="h-4 w-4" /> },
|
|
223
|
+
{
|
|
224
|
+
id: "failed",
|
|
225
|
+
label: "Recent failed",
|
|
226
|
+
icon: <AlertTriangle className="h-4 w-4" />,
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
id: "completed",
|
|
230
|
+
label: "Recent completed",
|
|
231
|
+
icon: <CheckCircle2 className="h-4 w-4" />,
|
|
232
|
+
},
|
|
233
|
+
] as const;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Queue Runtime panel. Aggregated counts, then a paginated tabbed listing
|
|
237
|
+
* of Active / Recent failed / Recent completed jobs. Job payloads are
|
|
238
|
+
* deliberately not surfaced — they may carry secrets.
|
|
239
|
+
*/
|
|
240
|
+
export const QueueRuntimePanel = () => {
|
|
241
|
+
const queueClient = usePluginClient(QueueApi);
|
|
242
|
+
const { data: stats, isLoading, error } = queueClient.getStats.useQuery(
|
|
243
|
+
undefined,
|
|
244
|
+
{ refetchInterval: REFRESH_INTERVAL_MS },
|
|
245
|
+
);
|
|
246
|
+
const [activeSubTab, setActiveSubTab] = useState<JobStateDto>("pending");
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<div className="space-y-4">
|
|
250
|
+
<InstanceScopeBanner
|
|
251
|
+
scope={stats?.scope ?? "instance"}
|
|
252
|
+
subject="Queue"
|
|
253
|
+
recommendation="Switch to a Redis-backed queue (e.g. BullMQ) for cluster-wide visibility."
|
|
254
|
+
/>
|
|
255
|
+
|
|
256
|
+
<Card>
|
|
257
|
+
<CardHeader>
|
|
258
|
+
<CardTitle className="flex items-center gap-2">
|
|
259
|
+
<Activity className="h-5 w-5" />
|
|
260
|
+
Queue Runtime
|
|
261
|
+
</CardTitle>
|
|
262
|
+
<CardDescription>
|
|
263
|
+
Live aggregated job counts. Refreshes every{" "}
|
|
264
|
+
{REFRESH_INTERVAL_MS / 1000}s.
|
|
265
|
+
</CardDescription>
|
|
266
|
+
</CardHeader>
|
|
267
|
+
<CardContent className="space-y-6">
|
|
268
|
+
{error ? (
|
|
269
|
+
<div className="text-sm text-destructive">
|
|
270
|
+
Failed to load queue stats.
|
|
271
|
+
</div>
|
|
272
|
+
) : (
|
|
273
|
+
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
|
274
|
+
<CountTile
|
|
275
|
+
label="Pending"
|
|
276
|
+
value={isLoading ? undefined : stats?.pending}
|
|
277
|
+
icon={Clock}
|
|
278
|
+
tone="warning"
|
|
279
|
+
/>
|
|
280
|
+
<CountTile
|
|
281
|
+
label="Processing"
|
|
282
|
+
value={isLoading ? undefined : stats?.processing}
|
|
283
|
+
icon={Loader2}
|
|
284
|
+
tone="default"
|
|
285
|
+
/>
|
|
286
|
+
<CountTile
|
|
287
|
+
label="Completed"
|
|
288
|
+
value={isLoading ? undefined : stats?.completed}
|
|
289
|
+
icon={CheckCircle2}
|
|
290
|
+
tone="success"
|
|
291
|
+
/>
|
|
292
|
+
<CountTile
|
|
293
|
+
label="Failed"
|
|
294
|
+
value={isLoading ? undefined : stats?.failed}
|
|
295
|
+
icon={AlertTriangle}
|
|
296
|
+
tone="danger"
|
|
297
|
+
/>
|
|
298
|
+
</div>
|
|
299
|
+
)}
|
|
300
|
+
|
|
301
|
+
<div className="space-y-3">
|
|
302
|
+
<Tabs
|
|
303
|
+
items={SUB_TABS.map((t) => ({
|
|
304
|
+
id: t.id,
|
|
305
|
+
label: t.label,
|
|
306
|
+
icon: t.icon,
|
|
307
|
+
}))}
|
|
308
|
+
activeTab={activeSubTab}
|
|
309
|
+
onTabChange={(id) => setActiveSubTab(id as JobStateDto)}
|
|
310
|
+
/>
|
|
311
|
+
<TabPanel id="pending" activeTab={activeSubTab}>
|
|
312
|
+
<JobsTable state="pending" />
|
|
313
|
+
</TabPanel>
|
|
314
|
+
<TabPanel id="active" activeTab={activeSubTab}>
|
|
315
|
+
<JobsTable state="active" />
|
|
316
|
+
</TabPanel>
|
|
317
|
+
<TabPanel id="failed" activeTab={activeSubTab}>
|
|
318
|
+
<JobsTable state="failed" />
|
|
319
|
+
</TabPanel>
|
|
320
|
+
<TabPanel id="completed" activeTab={activeSubTab}>
|
|
321
|
+
<JobsTable state="completed" />
|
|
322
|
+
</TabPanel>
|
|
323
|
+
</div>
|
|
324
|
+
</CardContent>
|
|
325
|
+
</Card>
|
|
326
|
+
</div>
|
|
327
|
+
);
|
|
328
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createFrontendPlugin,
|
|
3
|
+
createSlotExtension,
|
|
4
|
+
} from "@checkstack/frontend-api";
|
|
5
|
+
import { InfrastructureTabsSlot } from "@checkstack/infrastructure-common";
|
|
3
6
|
import { pluginMetadata, queueAccess } from "@checkstack/queue-common";
|
|
4
|
-
import {
|
|
7
|
+
import { QueueInfrastructureTab } from "./components/QueueInfrastructureTab";
|
|
5
8
|
import { Gauge } from "lucide-react";
|
|
6
9
|
|
|
7
|
-
// Register queue tab into the Infrastructure Configuration page
|
|
8
|
-
registerInfrastructureTab({
|
|
9
|
-
id: "queue",
|
|
10
|
-
pluginId: pluginMetadata.pluginId,
|
|
11
|
-
label: "Queue",
|
|
12
|
-
icon: Gauge,
|
|
13
|
-
component: QueueConfigTab,
|
|
14
|
-
readAccess: queueAccess.settings.read,
|
|
15
|
-
manageAccess: queueAccess.settings.manage,
|
|
16
|
-
order: 10, // First tab
|
|
17
|
-
});
|
|
18
|
-
|
|
19
10
|
export const queuePlugin = createFrontendPlugin({
|
|
20
11
|
metadata: pluginMetadata,
|
|
21
|
-
// No routes — the queue tab lives inside the infrastructure page
|
|
22
|
-
|
|
12
|
+
// No routes — the queue tab lives inside the infrastructure page.
|
|
13
|
+
extensions: [
|
|
14
|
+
createSlotExtension(InfrastructureTabsSlot, {
|
|
15
|
+
id: "queue.infrastructure.tab",
|
|
16
|
+
component: QueueInfrastructureTab,
|
|
17
|
+
metadata: {
|
|
18
|
+
label: "Queue",
|
|
19
|
+
icon: Gauge,
|
|
20
|
+
readAccess: queueAccess.settings.read,
|
|
21
|
+
manageAccess: queueAccess.settings.manage,
|
|
22
|
+
order: 10,
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
23
26
|
});
|
|
24
27
|
|
|
25
28
|
export * from "./api";
|