@pikku/queue-pg-boss 0.12.5 → 0.12.7

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,25 @@
1
+ ## 0.12.7
2
+
3
+ ### Patch Changes
4
+
5
+ - 6c30861: fix workflow step retry backoff firing immediately
6
+ - `@pikku/queue-pg-boss`: `backoff: 'exponential'` mapped to `retryBackoff: true` without a base `retryDelay`; pg-boss computes exponential backoff as `retry_delay * 2^n` with a queue default of 0, so every retry fired immediately. Exponential backoff now gets a 1s base delay, and sub-second fixed delays round up to 1s instead of flooring to 0 (= immediate).
7
+ - `@pikku/core`: a duration-string `retryDelay` (e.g. `'15s'`) on a workflow step was silently dropped (only numbers were honored) and fell back to exponential. It now resolves to a fixed backoff via `getDurationInMilliseconds`.
8
+
9
+ - Updated dependencies [6c30861]
10
+ - @pikku/core@0.12.56
11
+
12
+ ## 0.12.6
13
+
14
+ ### Patch Changes
15
+
16
+ - 41ce2cb: Upgrade to TypeScript 6 and raise the minimum Node.js version to 22.
17
+
18
+ All packages now build against `typescript@^6.0.3` and declare `engines.node >= 22`. Internal tooling (`ts-json-schema-generator`, `zod-to-ts`) was bumped to TypeScript 6-compatible releases.
19
+
20
+ - Updated dependencies [41ce2cb]
21
+ - @pikku/core@0.12.44
22
+
1
23
  ## 0.12.5
2
24
 
3
25
  ### Patch Changes
@@ -15,16 +15,19 @@ export const mapPikkuJobToPgBoss = (options) => {
15
15
  pgBossOptions.retryLimit = options.attempts - 1;
16
16
  }
17
17
  if (options?.backoff !== undefined) {
18
- if (typeof options.backoff === 'string') {
19
- // If backoff is a string, assume it's 'exponential' or 'fixed'
20
- pgBossOptions.retryBackoff = options.backoff === 'exponential';
18
+ const type = typeof options.backoff === 'string' ? options.backoff : options.backoff.type;
19
+ const delay = typeof options.backoff === 'object' ? options.backoff.delay : undefined;
20
+ pgBossOptions.retryBackoff = type === 'exponential';
21
+ if (delay !== undefined) {
22
+ // pg-boss uses seconds, we use milliseconds — never round a sub-second
23
+ // delay down to 0, which pg-boss treats as retry-immediately
24
+ pgBossOptions.retryDelay = Math.max(1, Math.round(delay / 1000));
21
25
  }
22
- else if (typeof options.backoff === 'object') {
23
- pgBossOptions.retryBackoff = options.backoff.type === 'exponential';
24
- if (options.backoff.delay !== undefined) {
25
- // pg-boss uses seconds, we use milliseconds
26
- pgBossOptions.retryDelay = Math.floor(options.backoff.delay / 1000);
27
- }
26
+ else if (type === 'exponential') {
27
+ // pg-boss computes exponential backoff as retry_delay * 2^n, and the
28
+ // queue-level retry_delay defaults to 0 — without an explicit base every
29
+ // "exponential" retry fires immediately. 1s base → ~1s, 2s, 4s, 8s…
30
+ pgBossOptions.retryDelay = 1;
28
31
  }
29
32
  }
30
33
  if (options?.removeOnComplete !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/queue-pg-boss",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -15,13 +15,13 @@
15
15
  "prepublishOnly": "yarn build"
16
16
  },
17
17
  "peerDependencies": {
18
- "@pikku/core": "^0.12.43"
18
+ "@pikku/core": "^0.12.56"
19
19
  },
20
20
  "dependencies": {
21
21
  "pg-boss": "^12.14.0"
22
22
  },
23
23
  "devDependencies": {
24
- "typescript": "^5.9"
24
+ "typescript": "^6.0.3"
25
25
  },
26
26
  "exports": {
27
27
  ".": "./dist/index.js"
package/run-tests.sh CHANGED
@@ -1,5 +1,56 @@
1
1
  #!/bin/bash
2
- cd "$(dirname "$0")"
2
+
3
+ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
+ cd "$script_dir"
5
+
6
+ # Enable nullglob to handle cases where no files match the pattern
7
+ shopt -s nullglob
8
+
9
+ # Initialize variables for options
10
+ watch_mode=false
11
+ coverage_mode=false
12
+
13
+ # Parse command-line options
14
+ while [[ $# -gt 0 ]]; do
15
+ case $1 in
16
+ --watch)
17
+ watch_mode=true
18
+ shift
19
+ ;;
20
+ --coverage)
21
+ coverage_mode=true
22
+ shift
23
+ ;;
24
+ *)
25
+ echo "Unknown option: $1"
26
+ exit 1
27
+ ;;
28
+ esac
29
+ done
30
+
31
+ # Define the pattern to match your test files
32
+ pattern="src/*.test.ts"
33
+
34
+ # Expand the pattern into an array of files
3
35
  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[@]}"
36
+
37
+ # Check if any files matched the pattern
38
+ if [ ${#files[@]} -eq 0 ]; then
39
+ echo "No test files found matching pattern: $pattern"
40
+ exit 0
41
+ fi
42
+
43
+ # Construct the node command
44
+ node_cmd=(node --import tsx --test)
45
+
46
+ # Append options based on flags
47
+ if [ "$watch_mode" = true ]; then
48
+ node_cmd+=(--watch)
49
+ fi
50
+
51
+ if [ "$coverage_mode" = true ]; then
52
+ node_cmd+=(--test-coverage-include="src/**/*.{ts,js}" --test-coverage-exclude="**/dist/**" --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info)
53
+ fi
54
+
55
+ # Execute the node command with the expanded list of files
56
+ "${node_cmd[@]}" "${files[@]}"
@@ -16,12 +16,20 @@ describe('mapPikkuJobToPgBoss — retry mapping', () => {
16
16
  assert.equal(mapPikkuJobToPgBoss({ attempts: 1 }).retryLimit, 0)
17
17
  })
18
18
 
19
- test("backoff 'exponential' → retryBackoff true", () => {
20
- assert.equal(
21
- mapPikkuJobToPgBoss({ attempts: 6, backoff: 'exponential' })
22
- .retryBackoff,
23
- true
24
- )
19
+ test("backoff 'exponential' → retryBackoff true + 1s base delay", () => {
20
+ const opts = mapPikkuJobToPgBoss({ attempts: 6, backoff: 'exponential' })
21
+ assert.equal(opts.retryBackoff, true)
22
+ // pg-boss multiplies retry_delay by 2^n and the queue default is 0 —
23
+ // without a base, "exponential" retries all fire immediately.
24
+ assert.equal(opts.retryDelay, 1)
25
+ })
26
+
27
+ test('sub-second fixed delay rounds up to 1s, not down to immediate', () => {
28
+ const opts = mapPikkuJobToPgBoss({
29
+ attempts: 4,
30
+ backoff: { type: 'fixed', delay: 300 },
31
+ })
32
+ assert.equal(opts.retryDelay, 1)
25
33
  })
26
34
 
27
35
  test('fixed backoff → retryBackoff false + retryDelay in seconds', () => {
@@ -25,15 +25,20 @@ export const mapPikkuJobToPgBoss = (
25
25
  }
26
26
 
27
27
  if (options?.backoff !== undefined) {
28
- if (typeof options.backoff === 'string') {
29
- // If backoff is a string, assume it's 'exponential' or 'fixed'
30
- pgBossOptions.retryBackoff = options.backoff === 'exponential'
31
- } else if (typeof options.backoff === 'object') {
32
- pgBossOptions.retryBackoff = options.backoff.type === 'exponential'
33
- if (options.backoff.delay !== undefined) {
34
- // pg-boss uses seconds, we use milliseconds
35
- pgBossOptions.retryDelay = Math.floor(options.backoff.delay / 1000)
36
- }
28
+ const type =
29
+ typeof options.backoff === 'string' ? options.backoff : options.backoff.type
30
+ const delay =
31
+ typeof options.backoff === 'object' ? options.backoff.delay : undefined
32
+ pgBossOptions.retryBackoff = type === 'exponential'
33
+ if (delay !== undefined) {
34
+ // pg-boss uses seconds, we use milliseconds — never round a sub-second
35
+ // delay down to 0, which pg-boss treats as retry-immediately
36
+ pgBossOptions.retryDelay = Math.max(1, Math.round(delay / 1000))
37
+ } else if (type === 'exponential') {
38
+ // pg-boss computes exponential backoff as retry_delay * 2^n, and the
39
+ // queue-level retry_delay defaults to 0 — without an explicit base every
40
+ // "exponential" retry fires immediately. 1s base → ~1s, 2s, 4s, 8s…
41
+ pgBossOptions.retryDelay = 1
37
42
  }
38
43
  }
39
44
 
@@ -1 +1 @@
1
- {"root":["./src/index.ts","./src/pg-boss-queue-service.ts","./src/pg-boss-queue-worker.ts","./src/pg-boss-scheduler-service.ts","./src/pg-boss-service-factory.ts","./src/utils.ts"],"version":"5.9.3"}
1
+ {"root":["./src/index.ts","./src/pg-boss-queue-service.ts","./src/pg-boss-queue-worker.ts","./src/pg-boss-scheduler-service.ts","./src/pg-boss-service-factory.ts","./src/utils.ts"],"version":"6.0.3"}