@pikku/queue-pg-boss 0.12.3 → 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 CHANGED
@@ -1,3 +1,66 @@
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
 
3
66
  ## 0.12.3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/queue-pg-boss",
3
- "version": "0.12.3",
3
+ "version": "0.12.4",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -8,18 +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
14
  "release": "npm run build && npm test",
14
15
  "prepublishOnly": "yarn build"
15
16
  },
16
17
  "peerDependencies": {
17
- "@pikku/core": "^0.12.9"
18
+ "@pikku/core": "^0.12.38"
18
19
  },
19
20
  "dependencies": {
20
21
  "pg-boss": "^12.14.0"
21
22
  },
22
23
  "devDependencies": {
23
24
  "typescript": "^5.9"
25
+ },
26
+ "exports": {
27
+ ".": "./dist/index.js"
24
28
  }
25
29
  }
package/run-tests.sh CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/bin/bash
2
2
  cd "$(dirname "$0")"
3
- node --loader tsx --test --experimental-test-coverage src/**/*.test.ts "$@"
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 setJobRunner before registerQueues', async () => {
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
- 'PgBossQueueWorkers requires setJobRunner() before registerQueues()',
12
+ 'Logger is required for registerQueues — pass it explicitly or ensure singleton services are initialized first',
13
13
  })
14
14
  })
15
15
  })