pg-boss 10.3.2 → 10.4.0

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.
@@ -0,0 +1,15 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(node:*)",
5
+ "Bash(for:*)",
6
+ "Bash(do mv \"$file\" \"$file%.js.ts\")",
7
+ "Bash(done)",
8
+ "Bash(find:*)",
9
+ "Bash(npm test:*)",
10
+ "mcp__ide__getDiagnostics"
11
+ ],
12
+ "deny": [],
13
+ "ask": []
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-boss",
3
- "version": "10.3.2",
3
+ "version": "10.4.0",
4
4
  "description": "Queueing jobs in Postgres from Node.js like a boss",
5
5
  "main": "./src/index.js",
6
6
  "engines": {
@@ -8,12 +8,12 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "cron-parser": "^4.9.0",
11
- "pg": "^8.16.0",
11
+ "pg": "^8.16.3",
12
12
  "serialize-error": "^8.1.0"
13
13
  },
14
14
  "devDependencies": {
15
- "@types/node": "^20.17.57",
16
- "luxon": "^3.6.1",
15
+ "@types/node": "^20.19.13",
16
+ "luxon": "^3.7.2",
17
17
  "mocha": "^10.8.2",
18
18
  "nyc": "^17.1.0",
19
19
  "standard": "^17.1.2"
package/src/plans.js CHANGED
@@ -506,7 +506,7 @@ function insertVersion (schema, version) {
506
506
  function fetchNextJob (schema) {
507
507
  return ({ includeMetadata, priority = true, ignoreStartAfter = false } = {}) => `
508
508
  WITH next as (
509
- SELECT id
509
+ SELECT id, singleton_key, policy
510
510
  FROM ${schema}.job
511
511
  WHERE name = $1
512
512
  AND state < '${JOB_STATES.active}'
@@ -514,13 +514,28 @@ function fetchNextJob (schema) {
514
514
  ORDER BY ${priority ? 'priority desc, ' : ''}created_on, id
515
515
  LIMIT $2
516
516
  FOR UPDATE SKIP LOCKED
517
+ ), grouped as (
518
+ SELECT
519
+ n.id,
520
+ n.policy as grouped_policy,
521
+ row_number() OVER (
522
+ PARTITION BY CASE
523
+ WHEN $2 > 1 AND n.policy in ('${QUEUE_POLICIES.singleton}', '${QUEUE_POLICIES.stately}') THEN n.singleton_key -- gate singleton/stately by key per batch
524
+ ELSE n.id::text
525
+ END
526
+ ) as row_number
527
+ FROM next n
517
528
  )
518
529
  UPDATE ${schema}.job j SET
519
530
  state = '${JOB_STATES.active}',
520
531
  started_on = now(),
521
532
  retry_count = CASE WHEN started_on IS NOT NULL THEN retry_count + 1 ELSE retry_count END
522
- FROM next
523
- WHERE name = $1 AND j.id = next.id
533
+ FROM grouped
534
+ WHERE name = $1 AND j.id = grouped.id
535
+ AND (
536
+ (grouped.grouped_policy IN ('${QUEUE_POLICIES.singleton}', '${QUEUE_POLICIES.stately}') AND grouped.row_number = 1) -- only one per singleton key
537
+ OR COALESCE(grouped.grouped_policy, '') NOT IN ('${QUEUE_POLICIES.singleton}', '${QUEUE_POLICIES.stately}') -- other policies unaffected
538
+ )
524
539
  RETURNING j.${includeMetadata ? allJobColumns : baseJobColumns}
525
540
  `
526
541
  }
package/types.d.ts CHANGED
@@ -25,7 +25,7 @@ declare namespace PgBoss {
25
25
  application_name?: string;
26
26
  database?: string;
27
27
  user?: string;
28
- password?: string;
28
+ password?: string | (() => string) | (() => Promise<string>);
29
29
  host?: string;
30
30
  port?: number;
31
31
  schema?: string;
@@ -370,6 +370,8 @@ declare class PgBoss extends EventEmitter {
370
370
  schedule(name: string, cron: string, data?: object, options?: PgBoss.ScheduleOptions): Promise<void>;
371
371
  unschedule(name: string): Promise<void>;
372
372
  getSchedules(): Promise<PgBoss.Schedule[]>;
373
+
374
+ getDb(): PgBoss.Db;
373
375
  }
374
376
 
375
377
  export = PgBoss;