@checkstack/queue-api 0.2.18 → 0.3.1

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 CHANGED
@@ -1,5 +1,133 @@
1
1
  # @checkstack/queue-api
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @checkstack/backend-api@0.15.2
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - aa89bc5: Replace the bespoke `registerInfrastructureTab()` registry with a standard
14
+ slot-extension contract (`InfrastructureTabsSlot` from
15
+ `@checkstack/infrastructure-common`). Plugins now contribute infrastructure
16
+ tabs via `createSlotExtension`, depending only on the slot owner.
17
+
18
+ The slot system in `@checkstack/frontend-api` gains a second type parameter
19
+ on `createSlot<TContext, TMetadata>` so extensions can declare typed static
20
+ metadata at registration time (label, icon, access rules, ordering for the
21
+ infrastructure tab bar). A new `useSlotExtensions(slot)` hook returns typed
22
+ extensions and subscribes to plugin lifecycle changes.
23
+
24
+ Each tab body now stacks a **Runtime** sub-section (live state, read-only)
25
+ on top of a **Configuration** sub-section (settings, gated by `canUpdate`).
26
+
27
+ **Queue runtime panel.** Surfaces aggregated counts (pending / processing /
28
+ completed / failed) plus three sub-tabs of recent jobs: **Active**, **Recent
29
+ failed** (with the failure message), and **Recent completed** (with
30
+ duration). Job payloads are deliberately not surfaced — they may carry
31
+ secrets and need a separate manage-access gate to be shown.
32
+
33
+ To support this, `Queue<T>` gains a required `listJobs(opts)` method
34
+ returning `JobSummary[]` (no payloads), and `QueueStats` gains a
35
+ `scope: "instance" | "cluster"` field. The in-memory queue keeps rolling
36
+ ring buffers (200 entries) for completed/failed history and tracks active
37
+ jobs by id; BullMQ uses native `getJobs`. `QueueManager.listJobs` aggregates
38
+ across queues and sorts (most-recent-first for terminal states, FIFO for
39
+ active/waiting/delayed).
40
+
41
+ **Cache runtime panel.** Lists the top N entries by size (or by recency) so
42
+ operators can debug a cache filling up. Values are deliberately omitted —
43
+ PII / secret risk. Backends opt in via an optional `listEntries?` method on
44
+ `CacheProvider`; non-supporting backends return `{ supported: false }` and
45
+ the UI renders a "not supported by this backend" hint. The in-memory cache
46
+ implements it using its existing per-entry byte tracking.
47
+
48
+ `CacheStats` also gains `scope: "instance" | "cluster"`.
49
+
50
+ **Multi-instance scope warning.** A new `<InstanceScopeBanner>` component in
51
+ `@checkstack/ui` renders a yellow banner above any runtime panel whose
52
+ backend reports `scope: "instance"` — i.e. in-memory queue or cache running
53
+ in a horizontally scaled deployment. The banner explains the metrics are
54
+ local to the responding replica and recommends switching to a clustered
55
+ backend (Redis-backed queue / cache) for cluster-wide visibility.
56
+
57
+ **Bug fix — stable cache provider proxy.** `CacheManagerImpl.getProvider()`
58
+ now returns a single stable proxy that delegates to whatever provider is
59
+ currently active. Previously, consumers of `createCachedScope` (and any
60
+ direct `cacheManager.getProvider()` caller) captured the active provider
61
+ reference at plugin-init time. After any `setActiveBackend` call — including
62
+ saving the same memory config in the new Cache tab, which reconstructs the
63
+ in-memory cache — those scopes wrote to an orphaned old provider while the
64
+ runtime panel read stats from the new (empty) one, making the runtime panel
65
+ appear to report 0 keys. With the proxy, all consumers share a single stable
66
+ identity and writes always land in the active provider.
67
+
68
+ **Bytes tracking on the in-memory cache.** `InMemoryCache.getStats().sizeBytes`
69
+ now returns a running approximation (UTF-8 bytes of the key plus
70
+ `v8.serialize(value).byteLength`, with a JSON fallback) that's kept in sync
71
+ across all eviction paths. Treat the number as a sanity gauge; it doesn't
72
+ include `Map` per-entry overhead.
73
+
74
+ **Pagination.** Both `Queue<T>.listJobs` and `CacheProvider.listEntries?`
75
+ are offset-paginated. Inputs gain an `offset: number`; outputs change to
76
+ `{ items, total: number | null, hasMore: boolean }`. `total` is nullable
77
+ so backends that can't compute it cheaply still paginate via `hasMore`.
78
+ The UI uses the existing `<Pagination>` component with a 25-row default
79
+ page size. `QueueManager.listJobs` aggregates by over-fetching
80
+ `[0, offset+limit)` per queue, merge-sorting, then slicing the window —
81
+ optimal for the single-queue case, acceptable for the multi-queue case
82
+ within the UI's reasonable page-depth bounds. BullMQ uses native offset
83
+ ranges via `getJobs(types, start, end)` plus `getJobCounts` for `total`.
84
+
85
+ **Pending tab.** The Queue runtime panel exposes a virtual `"pending"`
86
+ state (waiting ∪ delayed, FIFO). It's now the default sub-tab, since
87
+ "what's queued up?" is the most common question. Per-row state is shown
88
+ when viewing the combined list.
89
+
90
+ **Recurring schedules visible under Pending.** Cron- and interval-based
91
+ recurring jobs (e.g. healthchecks) are surfaced under Pending/Delayed
92
+ between fires, with a `nextRunAt` countdown column and a "(recurring)"
93
+ label. `JobSummary` gains optional `nextRunAt: Date` and `recurring:
94
+ boolean` fields. The in-memory queue synthesises these rows from its
95
+ `recurringJobs` registry; BullMQ already materialises the next fire of
96
+ each scheduler as a delayed job and we now surface its trigger time and
97
+ the `repeatJobKey`-derived `recurring` flag.
98
+
99
+ **Bug fix — drop hook emits with no listeners.** `EventBus.emit` no
100
+ longer enqueues a job when zero listeners (distributed or instance-local)
101
+ are registered for the hook. Previously, hooks like
102
+ `core.plugin.initialized` — emitted on every plugin init but subscribed
103
+ to by nothing in the core repo — accumulated one waiting job per emit
104
+ forever. The in-memory queue's `processNext` short-circuits when there
105
+ are zero consumer groups, so its post-loop cleanup never ran for these
106
+ orphaned jobs. The fix drops the emit at the source and logs a debug
107
+ line. Note: in distributed deployments using a Redis-backed queue, this
108
+ means a subscriber on another replica won't receive an event if no
109
+ replica that emits it has a local listener. Plugins needing cross-process
110
+ delivery must register their listener on every replica that should
111
+ receive the hook.
112
+
113
+ **Breaking notes (treated as minor under beta semantics)**:
114
+
115
+ - `@checkstack/infrastructure-common` removes `registerInfrastructureTab`
116
+ and `getInfrastructureTabs`; former callers must register an extension
117
+ into `InfrastructureTabsSlot`.
118
+ - `@checkstack/queue-api`'s `Queue<T>` interface requires the new
119
+ `listJobs(opts)` method returning `ListJobsResult` (paginated). Both
120
+ bundled queue backends (memory, BullMQ) are updated; out-of-tree
121
+ implementations will need to add it.
122
+ - `QueueStats` and `CacheStats` add a required `scope` field.
123
+ - `CacheProvider.listEntries?` (when implemented) now returns
124
+ `ListEntriesResult` instead of `CacheEntrySummary[]`.
125
+ - `JobState` adds a `"pending"` variant.
126
+
127
+ ### Patch Changes
128
+
129
+ - @checkstack/backend-api@0.15.1
130
+
3
131
  ## 0.2.18
4
132
 
5
133
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/queue-api",
3
- "version": "0.2.18",
3
+ "version": "0.3.1",
4
4
  "license": "Elastic-2.0",
5
5
  "checkstack": {
6
6
  "type": "tooling"
@@ -8,12 +8,12 @@
8
8
  "type": "module",
9
9
  "main": "src/index.ts",
10
10
  "dependencies": {
11
- "@checkstack/backend-api": "0.14.1",
11
+ "@checkstack/backend-api": "0.15.1",
12
12
  "zod": "^4.0.0"
13
13
  },
14
14
  "devDependencies": {
15
- "@checkstack/tsconfig": "0.0.6",
16
- "@checkstack/scripts": "0.1.2"
15
+ "@checkstack/tsconfig": "0.0.7",
16
+ "@checkstack/scripts": "0.3.1"
17
17
  },
18
18
  "scripts": {
19
19
  "typecheck": "tsgo -b",
@@ -1,5 +1,11 @@
1
1
  import { z } from "zod";
2
- import type { Queue, QueueStats, RecurringSchedule } from "./queue";
2
+ import type {
3
+ Queue,
4
+ QueueStats,
5
+ RecurringSchedule,
6
+ ListJobsOptions,
7
+ ListJobsResult,
8
+ } from "./queue";
3
9
  import type { Migration, Logger } from "@checkstack/backend-api";
4
10
 
5
11
  export interface QueuePlugin<Config = unknown> {
@@ -89,6 +95,12 @@ export interface QueueManager {
89
95
  */
90
96
  getAggregatedStats(): Promise<QueueStats>;
91
97
 
98
+ /**
99
+ * Aggregate {@link Queue.listJobs} across all queues, sorted into a single
100
+ * paginated list. Used by the Infrastructure runtime panel.
101
+ */
102
+ listJobs(opts: ListJobsOptions): Promise<ListJobsResult>;
103
+
92
104
  /**
93
105
  * List all recurring jobs across all queues.
94
106
  * Used for migration preview.
package/src/queue.ts CHANGED
@@ -152,6 +152,24 @@ export interface Queue<T = unknown> {
152
152
  * Get queue statistics
153
153
  */
154
154
  getStats(): Promise<QueueStats>;
155
+
156
+ /**
157
+ * List jobs in a particular state for the Infrastructure runtime panel,
158
+ * paginated.
159
+ *
160
+ * Implementations MUST:
161
+ * - Return summaries only (no payloads).
162
+ * - Honour `opts.offset` and `opts.limit`.
163
+ * - For `completed` / `failed`: return the most recent first.
164
+ * - For `active` / `waiting` / `delayed`: return the oldest first
165
+ * (FIFO order — what users typically want to see).
166
+ * - Set `total` to a cheap exact count when possible, or `null` when not.
167
+ * - Set `hasMore` correctly so the UI can disable the "next" control.
168
+ *
169
+ * Backends without affordable history (e.g. fire-and-forget transports)
170
+ * may return `{ items: [], total: 0, hasMore: false }` for terminal states.
171
+ */
172
+ listJobs(opts: ListJobsOptions): Promise<ListJobsResult>;
155
173
  }
156
174
 
157
175
  export interface QueueStats {
@@ -163,4 +181,87 @@ export interface QueueStats {
163
181
  * Number of active consumer groups
164
182
  */
165
183
  consumerGroups: number;
184
+ /**
185
+ * Whether these stats reflect the local process only (`"instance"`) or
186
+ * the entire deployment cluster (`"cluster"`). Backends that share state
187
+ * across replicas (e.g. BullMQ on Redis) report `"cluster"`. Backends
188
+ * that hold state in-process (e.g. the in-memory queue) report
189
+ * `"instance"`; in horizontally scaled deployments, each replica returns
190
+ * its own numbers.
191
+ */
192
+ scope: "instance" | "cluster";
193
+ }
194
+
195
+ /**
196
+ * Lifecycle states a job can be in. Mirrors BullMQ for consistency, with
197
+ * one virtual addition: `"pending"` is the union of `"waiting"` and
198
+ * `"delayed"`. Most operators think of "pending work" as both — the
199
+ * Infrastructure UI exposes it as a single tab, and the existing
200
+ * `QueueStats.pending` already aggregates both counts.
201
+ */
202
+ export type JobState =
203
+ | "pending"
204
+ | "waiting"
205
+ | "active"
206
+ | "delayed"
207
+ | "completed"
208
+ | "failed";
209
+
210
+ /**
211
+ * Inspection summary for a single job. Carries no payload — payloads can
212
+ * contain secrets, so they're surfaced (if at all) behind a separate
213
+ * manage-access RPC. The Infrastructure runtime panel uses these summaries
214
+ * for the Active / Failed / Completed sub-tables.
215
+ */
216
+ export interface JobSummary {
217
+ id: string;
218
+ /** Optional job/queue name for display. */
219
+ name?: string;
220
+ state: JobState;
221
+ /** Time the job was first enqueued. */
222
+ enqueuedAt: Date;
223
+ /** Time the job started processing, if applicable. */
224
+ startedAt?: Date;
225
+ /** Time the job finished (completed or failed), if applicable. */
226
+ finishedAt?: Date;
227
+ /** Attempts made so far (1-based on completion, 0 before first run). */
228
+ attempts: number;
229
+ /** Failure message, only set when `state === "failed"`. */
230
+ failedReason?: string;
231
+ /**
232
+ * For recurring schedules and delayed jobs: the absolute time of the
233
+ * next planned execution. Lets the UI render a "Next run" column for
234
+ * pending/delayed rows so cron-scheduled work (e.g. healthchecks) is
235
+ * visible between fires.
236
+ */
237
+ nextRunAt?: Date;
238
+ /**
239
+ * Whether this row represents a recurring schedule (cron / interval)
240
+ * rather than a one-shot enqueue. Used by the UI to label such rows
241
+ * distinctly so operators can tell scheduled work from ad-hoc work.
242
+ */
243
+ recurring?: boolean;
244
+ }
245
+
246
+ /**
247
+ * Options for {@link Queue.listJobs}. Offset-based pagination — backends
248
+ * that natively use cursors (BullMQ, Redis SCAN, etc.) translate internally.
249
+ */
250
+ export interface ListJobsOptions {
251
+ state: JobState;
252
+ /** Zero-based offset into the result set. */
253
+ offset: number;
254
+ /** Maximum summaries to return. Implementations should cap at a reasonable upper bound. */
255
+ limit: number;
256
+ }
257
+
258
+ /**
259
+ * Paginated result for {@link Queue.listJobs}.
260
+ */
261
+ export interface ListJobsResult {
262
+ items: JobSummary[];
263
+ /** Total job count for the requested state, or `null` if the backend can't compute it cheaply. */
264
+ total: number | null;
265
+ /** Whether more items exist past `offset + items.length`. */
266
+ hasMore: boolean;
166
267
  }