feat: add queue management handlers#1043
Conversation
Coverage Report for CI Build 29583752771Coverage increased (+0.4%) to 79.932%Details
Uncovered Changes
Coverage Regressions17 previously-covered lines in 1 file lost coverage.
Coverage Stats💛 - Coveralls |
cd05d02 to
8d0e084
Compare
8d0e084 to
db8596c
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds admin-facing queue overflow management capabilities for pg-boss “created” job backlogs, along with an operator CLI (npm scripts) to list backlog hotspots, archive (“backup”) created jobs into an overflow table, and restore them in controlled batches.
Changes:
- Added
QueueOverflowStorePgwith SQL-backed list/count/backup/restore operations and associated unit/integration tests. - Exposed new admin endpoints under
/queue/overflow,/queue/overflow/count,/queue/overflow/backup, and/queue/overflow/restorewith request schemas and disconnect-aware abort handling. - Added an operator CLI (
jobs-client.ts) + docs and wired npm scripts; refactoredpprof-client.tsto reuse shared integer parsers.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/admin-queue-overflow.test.ts | Integration coverage for admin queue overflow routes against a real pg-boss schema/tables. |
| src/scripts/README.md | Operator documentation for the jobs CLI and endpoint semantics. |
| src/scripts/pprof-client.ts | Reuses shared integer parsing helpers from @internal/parser. |
| src/scripts/jobs-client.ts | New CLI for listing/backing up/restoring created-job overflow via the admin API. |
| src/scripts/jobs-client.test.ts | Unit tests for CLI config parsing, request building, and restore throttling/backoff behavior. |
| src/internal/queue/queue.ts | Moves PG_BOSS_SCHEMA to constants and types Queue.getDb() as QueueDB. |
| src/internal/queue/overflow.ts | New queue overflow store implementing list/count/backup/restore with transactional + advisory-lock semantics. |
| src/internal/queue/overflow.test.ts | Unit tests validating filter normalization, SQL shapes, transaction/abort behavior, and move/restore semantics. |
| src/internal/queue/index.ts | Exports the new overflow module from the queue package. |
| src/internal/queue/database.ts | Adds beginTransaction() to QueueDB to support transactional maintenance operations. |
| src/internal/queue/constants.ts | Adds PG_BOSS_SCHEMA constant to shared queue constants. |
| src/internal/parser/string-list.ts | New helpers for normalizing string lists and parsing comma-separated env/query values. |
| src/internal/parser/string-list.test.ts | Tests for list normalization and comma-separated parsing behavior. |
| src/internal/parser/integer.ts | New strict integer parsers for non-negative and positive safe integers. |
| src/internal/parser/integer.test.ts | Tests for integer parsing strictness and bounds. |
| src/internal/parser/index.ts | Barrel export for new parser utilities. |
| src/internal/parser/boolean.ts | New strict optional-boolean parser used by the jobs CLI. |
| src/internal/parser/boolean.test.ts | Tests for optional-boolean parsing behavior. |
| src/internal/database/pg-connection.ts | Extends beginTransaction options to include abort signals; adds signal-aware pool checkout helper. |
| src/internal/database/pg-connection.test.ts | Tests for signal-aware transaction checkout and late-client release behavior. |
| src/http/routes/admin/queue.ts | Adds admin endpoints + JSON schemas for queue overflow list/count/backup/restore routes. |
| src/http/routes/admin/queue.test.ts | Ensures config initialization order for existing admin queue route tests. |
| package.json | Adds npm scripts for the jobs CLI (list/backup/restore). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return error | ||
| } | ||
|
|
||
| function acquirePoolClientWithSignal(pool: Pool, signal: AbortSignal): Promise<PoolClient> { |
There was a problem hiding this comment.
I'm worried that this function might caused some race conditions.
For example what if we abort the signal while a query is still ongoing and we call release?
It might create some issue. I'm not super confident that having an abort signal on acquisition when the signal can't be passed down to connect (which i'm not sure is cancellable)
There was a problem hiding this comment.
Yes, it isn't cancelable. I wanted to add here exactly because queue connection timeout is unbounded (for this case - incident, better to fail fast). Ideally, we should set it to a reasonable value but I didn't want to change it since it's operationally bigger, instead capped here so that we can retry.
For the case (running query and release), ownership is transferred and as usual, connection will be destroyed.
Also, added two new tests in the last commit for more confidence
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
be6c21c to
4472060
Compare
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
What kind of change does this PR introduce?
feat
What is the current behavior?
Manual queue management under load while jumping between systems.
What is the new behavior?
Admin app attaches endpoints for listing, backup and restore.
Add a client to attach it via npm scripts.
Additional context
Kind of playbook automation/ease of use.
Disabled orioledb for restore due to targetless on conflict incompatibility, that support isn't really needed.