@pikku/queue-pg-boss 0.12.2 → 0.12.4
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 +87 -0
- package/dist/pg-boss-queue-worker.d.ts +2 -1
- package/dist/pg-boss-queue-worker.js +7 -2
- package/package.json +8 -3
- package/run-tests.sh +3 -1
- package/src/pg-boss-queue-service.test.ts +51 -0
- package/src/pg-boss-queue-worker.test.ts +2 -2
- package/src/pg-boss-queue-worker.ts +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,92 @@
|
|
|
1
|
+
## 0.12.4
|
|
2
|
+
|
|
3
|
+
### Patch Changes
|
|
4
|
+
|
|
5
|
+
- 92cd5b1: feat(workflow): workflow-owned step retries + stable invocationId
|
|
6
|
+
|
|
7
|
+
The workflow — not the queue — now owns step retry policy, and each step
|
|
8
|
+
invocation gets a stable idempotency key.
|
|
9
|
+
- **Default `retries: 5` with exponential backoff.** A step with no `retries`
|
|
10
|
+
previously inherited the queue's bare default (e.g. pg-boss `retry_limit 2`,
|
|
11
|
+
no backoff) so retries fired instantly and couldn't outlast a transient
|
|
12
|
+
outage. Retries now default to 5 with backoff, resolved at the workflow layer.
|
|
13
|
+
- **`retries: 0` is honored.** Dispatch previously passed `undefined` options
|
|
14
|
+
for `retries: 0`, letting the queue re-run a non-idempotent step up to its own
|
|
15
|
+
default. The resolved policy now always sets `attempts` (`retries: 0` →
|
|
16
|
+
`attempts: 1`), so the queue never second-guesses the workflow. The persisted
|
|
17
|
+
step retries and the dispatched `attempts` are resolved together so
|
|
18
|
+
"retries exhausted" and "no more redeliveries" are the same event.
|
|
19
|
+
- **`workflowStep.invocationId`** — a deterministic, dependency-free
|
|
20
|
+
`uuidv5(runId:stepName)` handed to every step. Unlike `stepId` (minted per
|
|
21
|
+
attempt), it is identical across retries, so a step can dedupe on it
|
|
22
|
+
(`ON CONFLICT (invocationId)`, Stripe idempotency keys, etc.).
|
|
23
|
+
- **queue-bullmq**: `mapPikkuJobToBull` now maps `backoff` (previously dropped,
|
|
24
|
+
so a step's backoff silently never applied on Redis), and `registerQueues`
|
|
25
|
+
throws a clear error when no logger is available (matching queue-pg-boss).
|
|
26
|
+
- **Dispatch failures are recoverable, not fatal.** A step is now marked
|
|
27
|
+
`scheduled` only _after_ it is successfully handed to its transport (queue or
|
|
28
|
+
scheduler) — a failed hand-off leaves it `pending` so a replay re-dispatches
|
|
29
|
+
it, instead of stranding it in `scheduled` (replay would pause forever on a
|
|
30
|
+
job that was never enqueued). A transport outage (e.g. pg-boss momentarily
|
|
31
|
+
down) is surfaced as a new `WorkflowDispatchException`, which the orchestrator
|
|
32
|
+
treats as transient: the run is left running and the orchestrator job is
|
|
33
|
+
rethrown for redelivery (it replays idempotently from the snapshot) rather
|
|
34
|
+
than the whole run being marked `failed`. The orchestrator job now also
|
|
35
|
+
carries its own retry policy, so this holds even when the orchestrator queue
|
|
36
|
+
is configured `retry_limit 0`. A genuine step error still fails the run.
|
|
37
|
+
- **Same step name can be invoked multiple times in one run.** Step rows are now
|
|
38
|
+
keyed per _invocation_: the Nth reach of a step name in a replay resolves to a
|
|
39
|
+
physical key (`name` for the first, `name#N` for repeats), so a literal
|
|
40
|
+
duplicate name no longer clobbers the earlier step's state. The first reach
|
|
41
|
+
keeps the bare name, so existing rows, graph-node matching and `invocationId`s
|
|
42
|
+
are unchanged. Ordinals are derived deterministically from DSL execution order
|
|
43
|
+
and reset each replay.
|
|
44
|
+
- **Step provenance (`fromStepName`) + graph cycles.** Every step now records
|
|
45
|
+
the predecessor it was scheduled from (`fromStepName`; entry steps have none),
|
|
46
|
+
persisted on the step row across all stores (in-memory, kysely, redis,
|
|
47
|
+
mongodb, cloudflare DO) and carried in the queued payload. The DSL wire
|
|
48
|
+
exposes the derived `fromInvocationId` (`uuidv5(runId:fromStepName)`) so
|
|
49
|
+
consumers get the stable predecessor key without a second persisted id —
|
|
50
|
+
`fromStepName` is the source of truth (it is replay-deterministic; `stepId`,
|
|
51
|
+
minted per row, is not). This makes the walked path reconstructable even when
|
|
52
|
+
a node is reached more than once: in `a → b → a → c` the second `a` is a
|
|
53
|
+
distinct ordinal instance (`a#1`) whose `fromStepName` is `b`.
|
|
54
|
+
The graph runner now supports **cycles**: a forward edge into an
|
|
55
|
+
already-started node still collapses to a single run (joins/diamonds are
|
|
56
|
+
unchanged), but a _back-edge_ — one whose target can reach its source — fires
|
|
57
|
+
a fresh ordinal instance, so a node can loop back to itself. Termination is
|
|
58
|
+
the graph's responsibility (branch routing must converge); the engine enforces
|
|
59
|
+
no visit cap.
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [92cd5b1]
|
|
62
|
+
- @pikku/core@0.12.38
|
|
63
|
+
|
|
1
64
|
## 0.12.0
|
|
2
65
|
|
|
66
|
+
## 0.12.3
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- 8b9b2e9: Accept optional logger parameter in `registerQueues()` instead of reaching into pikku state directly. Falls back to `getSingletonServices()` for backwards compatibility.
|
|
71
|
+
- 8b9b2e9: Fix child workflow completion in queued execution mode. When a sub-workflow completes, the parent step is now marked as succeeded and the parent orchestrator resumes automatically via `onChildWorkflowCompleted`. Adds `parentStepId` to `WorkflowRunWire` to track the parent step without querying. Retains advisory locks in PgKyselyWorkflowService for concurrency safety. Fixes pgboss `registerQueues` to accept an optional logger parameter.
|
|
72
|
+
- Updated dependencies [e412b4d]
|
|
73
|
+
- Updated dependencies [53dc8c8]
|
|
74
|
+
- Updated dependencies [0a1cc51]
|
|
75
|
+
- Updated dependencies [0a1cc51]
|
|
76
|
+
- Updated dependencies [0a1cc51]
|
|
77
|
+
- Updated dependencies [0a1cc51]
|
|
78
|
+
- Updated dependencies [0a1cc51]
|
|
79
|
+
- Updated dependencies [0a1cc51]
|
|
80
|
+
- Updated dependencies [0a1cc51]
|
|
81
|
+
- Updated dependencies [0a1cc51]
|
|
82
|
+
- Updated dependencies [0a1cc51]
|
|
83
|
+
- Updated dependencies [8b9b2e9]
|
|
84
|
+
- Updated dependencies [8b9b2e9]
|
|
85
|
+
- Updated dependencies [b973d44]
|
|
86
|
+
- Updated dependencies [8b9b2e9]
|
|
87
|
+
- Updated dependencies [8b9b2e9]
|
|
88
|
+
- @pikku/core@0.12.9
|
|
89
|
+
|
|
3
90
|
## 0.12.2
|
|
4
91
|
|
|
5
92
|
### Patch Changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PgBoss, WorkOptions } from 'pg-boss';
|
|
2
2
|
import type { QueueWorkers, PikkuWorkerConfig, QueueConfigMapping, ConfigValidationResult } from '@pikku/core/queue';
|
|
3
|
+
import type { Logger } from '@pikku/core/services';
|
|
3
4
|
export declare const mapPikkuWorkerToPgBoss: (workerConfig?: PikkuWorkerConfig) => WorkOptions;
|
|
4
5
|
/**
|
|
5
6
|
* pg-boss/PostgreSQL queue worker implementation
|
|
@@ -19,5 +20,5 @@ export declare class PgBossQueueWorkers implements QueueWorkers {
|
|
|
19
20
|
/**
|
|
20
21
|
* Scan state and register all compatible processors
|
|
21
22
|
*/
|
|
22
|
-
registerQueues(): Promise<Record<string, ConfigValidationResult[]>>;
|
|
23
|
+
registerQueues(logger?: Logger): Promise<Record<string, ConfigValidationResult[]>>;
|
|
23
24
|
}
|
|
@@ -90,8 +90,13 @@ export class PgBossQueueWorkers {
|
|
|
90
90
|
/**
|
|
91
91
|
* Scan state and register all compatible processors
|
|
92
92
|
*/
|
|
93
|
-
async registerQueues() {
|
|
94
|
-
|
|
93
|
+
async registerQueues(logger) {
|
|
94
|
+
if (!logger) {
|
|
95
|
+
logger = pikkuState(null, 'package', 'singletonServices')?.logger;
|
|
96
|
+
}
|
|
97
|
+
if (!logger) {
|
|
98
|
+
throw new Error('Logger is required for registerQueues — pass it explicitly or ensure singleton services are initialized first');
|
|
99
|
+
}
|
|
95
100
|
return await registerQueueWorkers(this.configMappings, logger, async (queueName, processor) => {
|
|
96
101
|
await this.pgBoss.createQueue(queueName);
|
|
97
102
|
const workerId = await this.pgBoss.work(processor.name, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/queue-pg-boss",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"author": "yasser.fadl@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -8,17 +8,22 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"tsc": "tsc",
|
|
11
|
+
"test": "bash run-tests.sh",
|
|
11
12
|
"ncu": "npx npm-check-updates",
|
|
12
13
|
"build": "tsc -b",
|
|
13
|
-
"release": "npm run build && npm test"
|
|
14
|
+
"release": "npm run build && npm test",
|
|
15
|
+
"prepublishOnly": "yarn build"
|
|
14
16
|
},
|
|
15
17
|
"peerDependencies": {
|
|
16
|
-
"@pikku/core": "^0.12.
|
|
18
|
+
"@pikku/core": "^0.12.38"
|
|
17
19
|
},
|
|
18
20
|
"dependencies": {
|
|
19
21
|
"pg-boss": "^12.14.0"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
22
24
|
"typescript": "^5.9"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./dist/index.js"
|
|
23
28
|
}
|
|
24
29
|
}
|
package/run-tests.sh
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
cd "$(dirname "$0")"
|
|
3
|
-
|
|
3
|
+
files=($(find src -type f -name "*.test.ts"))
|
|
4
|
+
if [ ${#files[@]} -eq 0 ]; then echo "No test files found"; exit 0; fi
|
|
5
|
+
node --import tsx --test "$@" "${files[@]}"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { mapPikkuJobToPgBoss } from './pg-boss-queue-service.js'
|
|
5
|
+
|
|
6
|
+
// These guard the contract the workflow engine relies on: a step's resolved
|
|
7
|
+
// retry policy (attempts + backoff) must survive translation into pg-boss
|
|
8
|
+
// terms, so "workflow owns retries" actually reaches the queue.
|
|
9
|
+
describe('mapPikkuJobToPgBoss — retry mapping', () => {
|
|
10
|
+
test('attempts → retryLimit (attempts - 1)', () => {
|
|
11
|
+
// Default policy: 5 retries → 6 attempts → retryLimit 5.
|
|
12
|
+
assert.equal(mapPikkuJobToPgBoss({ attempts: 6 }).retryLimit, 5)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('attempts: 1 (retries: 0) → retryLimit 0 (pg-boss never re-runs it)', () => {
|
|
16
|
+
assert.equal(mapPikkuJobToPgBoss({ attempts: 1 }).retryLimit, 0)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test("backoff 'exponential' → retryBackoff true", () => {
|
|
20
|
+
assert.equal(
|
|
21
|
+
mapPikkuJobToPgBoss({ attempts: 6, backoff: 'exponential' })
|
|
22
|
+
.retryBackoff,
|
|
23
|
+
true
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('fixed backoff → retryBackoff false + retryDelay in seconds', () => {
|
|
28
|
+
const opts = mapPikkuJobToPgBoss({
|
|
29
|
+
attempts: 4,
|
|
30
|
+
backoff: { type: 'fixed', delay: 5000 },
|
|
31
|
+
})
|
|
32
|
+
assert.equal(opts.retryBackoff, false)
|
|
33
|
+
// pg-boss takes seconds; our delay is milliseconds.
|
|
34
|
+
assert.equal(opts.retryDelay, 5)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('exponential object backoff → retryBackoff true + retryDelay in seconds', () => {
|
|
38
|
+
const opts = mapPikkuJobToPgBoss({
|
|
39
|
+
attempts: 4,
|
|
40
|
+
backoff: { type: 'exponential', delay: 2000 },
|
|
41
|
+
})
|
|
42
|
+
assert.equal(opts.retryBackoff, true)
|
|
43
|
+
assert.equal(opts.retryDelay, 2)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('no options → no retry fields set', () => {
|
|
47
|
+
const opts = mapPikkuJobToPgBoss(undefined)
|
|
48
|
+
assert.equal(opts.retryLimit, undefined)
|
|
49
|
+
assert.equal(opts.retryBackoff, undefined)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -4,12 +4,12 @@ import assert from 'node:assert/strict'
|
|
|
4
4
|
import { PgBossQueueWorkers } from './pg-boss-queue-worker.js'
|
|
5
5
|
|
|
6
6
|
describe('PgBossQueueWorkers', () => {
|
|
7
|
-
test('requires
|
|
7
|
+
test('requires a logger (explicit or from singleton services)', async () => {
|
|
8
8
|
const workers = new PgBossQueueWorkers({} as any)
|
|
9
9
|
|
|
10
10
|
await assert.rejects(() => workers.registerQueues(), {
|
|
11
11
|
message:
|
|
12
|
-
'
|
|
12
|
+
'Logger is required for registerQueues — pass it explicitly or ensure singleton services are initialized first',
|
|
13
13
|
})
|
|
14
14
|
})
|
|
15
15
|
})
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
QueueJobDiscardedError,
|
|
13
13
|
} from '@pikku/core/queue'
|
|
14
14
|
import { pikkuState } from '@pikku/core/internal'
|
|
15
|
+
import type { Logger } from '@pikku/core/services'
|
|
15
16
|
import { mapPgBossJobToQueueJob } from './utils.js'
|
|
16
17
|
|
|
17
18
|
export const mapPikkuWorkerToPgBoss = (
|
|
@@ -128,8 +129,17 @@ export class PgBossQueueWorkers implements QueueWorkers {
|
|
|
128
129
|
/**
|
|
129
130
|
* Scan state and register all compatible processors
|
|
130
131
|
*/
|
|
131
|
-
async registerQueues(
|
|
132
|
-
|
|
132
|
+
async registerQueues(
|
|
133
|
+
logger?: Logger
|
|
134
|
+
): Promise<Record<string, ConfigValidationResult[]>> {
|
|
135
|
+
if (!logger) {
|
|
136
|
+
logger = pikkuState(null, 'package', 'singletonServices')?.logger
|
|
137
|
+
}
|
|
138
|
+
if (!logger) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
'Logger is required for registerQueues — pass it explicitly or ensure singleton services are initialized first'
|
|
141
|
+
)
|
|
142
|
+
}
|
|
133
143
|
|
|
134
144
|
return await registerQueueWorkers(
|
|
135
145
|
this.configMappings,
|