pg-boss 11.0.4 → 11.0.6

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/package.json CHANGED
@@ -1,25 +1,27 @@
1
1
  {
2
2
  "name": "pg-boss",
3
- "version": "11.0.4",
3
+ "version": "11.0.6",
4
4
  "description": "Queueing jobs in Postgres from Node.js like a boss",
5
5
  "main": "./src/index.js",
6
+ "type": "commonjs",
6
7
  "engines": {
7
8
  "node": ">=22"
8
9
  },
9
10
  "dependencies": {
10
- "cron-parser": "^4.9.0",
11
+ "cron-parser": "^5.4.0",
11
12
  "pg": "^8.16.3",
12
13
  "serialize-error": "^8.1.0"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@types/node": "^22",
17
+ "eslint": "^9.36.0",
16
18
  "luxon": "^3.7.2",
17
- "mocha": "^10.8.2",
18
- "nyc": "^17.1.0",
19
- "standard": "^17.1.2"
19
+ "mocha": "^11.7.4",
20
+ "neostandard": "^0.12.2",
21
+ "nyc": "^17.1.0"
20
22
  },
21
23
  "scripts": {
22
- "test": "standard && mocha",
24
+ "test": "eslint . && mocha",
23
25
  "cover": "nyc npm test",
24
26
  "tsc": "tsc --noEmit types.d.ts",
25
27
  "readme": "node ./test/readme.js",
@@ -45,17 +47,6 @@
45
47
  "text"
46
48
  ]
47
49
  },
48
- "standard": {
49
- "globals": [
50
- "describe",
51
- "it",
52
- "before",
53
- "after",
54
- "before",
55
- "beforeEach",
56
- "afterEach"
57
- ]
58
- },
59
50
  "repository": {
60
51
  "type": "git",
61
52
  "url": "git+https://github.com/timgit/pg-boss.git"
package/src/manager.js CHANGED
@@ -648,13 +648,13 @@ class Manager extends EventEmitter {
648
648
  async getQueueStats (name) {
649
649
  Attorney.assertQueueName(name)
650
650
 
651
- const { table } = await this.getQueueCache(name)
651
+ const queue = await this.getQueueCache(name)
652
652
 
653
- const sql = plans.getQueueStats(this.config.schema, table, [name])
653
+ const sql = plans.getQueueStats(this.config.schema, queue.table, [name])
654
654
 
655
655
  const { rows } = await this.db.executeSql(sql)
656
656
 
657
- return rows.at(0) || null
657
+ return Object.assign(queue, rows.at(0) || {})
658
658
  }
659
659
 
660
660
  async getJobById (name, id, options = {}) {
@@ -680,7 +680,9 @@ class Manager extends EventEmitter {
680
680
  return options.db
681
681
  }
682
682
 
683
- assert(this.db._pgbdb && this.db.opened, 'Database connection is not opened')
683
+ if (this.db._pgbdb) {
684
+ assert(this.db.opened, 'Database connection is not opened')
685
+ }
684
686
 
685
687
  return this.db
686
688
  }
package/src/plans.js CHANGED
@@ -702,7 +702,7 @@ function insertJobs (schema, { table, name, returnId = true }) {
702
702
  END as singleton_on,
703
703
  COALESCE("expireInSeconds", q.expire_seconds) as expire_seconds,
704
704
  COALESCE("deleteAfterSeconds", q.deletion_seconds) as deletion_seconds,
705
- COALESCE("keepUntil", COALESCE(j.start_after, now()) + q.retention_seconds * interval '1s') as keep_until,
705
+ j.start_after + (COALESCE("retentionSeconds", q.retention_seconds) * interval '1s') as keep_until,
706
706
  COALESCE("retryLimit", q.retry_limit) as retry_limit,
707
707
  COALESCE("retryDelay", q.retry_delay) as retry_delay,
708
708
  COALESCE("retryBackoff", q.retry_backoff, false) as retry_backoff,
@@ -730,7 +730,7 @@ function insertJobs (schema, { table, name, returnId = true }) {
730
730
  "singletonOffset" integer,
731
731
  "expireInSeconds" integer,
732
732
  "deleteAfterSeconds" integer,
733
- "keepUntil" timestamp with time zone
733
+ "retentionSeconds" integer
734
734
  )
735
735
  ) j
736
736
  JOIN ${schema}.queue q ON q.name = '${name}'
package/src/timekeeper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const EventEmitter = require('node:events')
2
2
  const plans = require('./plans')
3
- const cronParser = require('cron-parser')
3
+ const { CronExpressionParser } = require('cron-parser')
4
4
  const Attorney = require('./attorney')
5
5
 
6
6
  const QUEUES = {
@@ -144,7 +144,7 @@ class Timekeeper extends EventEmitter {
144
144
  }
145
145
 
146
146
  shouldSendIt (cron, tz) {
147
- const interval = cronParser.parseExpression(cron, { tz })
147
+ const interval = CronExpressionParser.parse(cron, { tz, strict: false })
148
148
 
149
149
  const prevTime = interval.prev()
150
150
 
@@ -176,7 +176,7 @@ class Timekeeper extends EventEmitter {
176
176
  async schedule (name, cron, data, options = {}) {
177
177
  const { tz = 'UTC', key = '', ...rest } = options
178
178
 
179
- cronParser.parseExpression(cron, { tz })
179
+ CronExpressionParser.parse(cron, { tz, strict: false })
180
180
 
181
181
  Attorney.checkSendArgs([name, data, { ...rest }])
182
182
  Attorney.assertKey(key)
package/types.d.ts CHANGED
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events'
3
3
  declare namespace PgBoss {
4
4
 
5
5
  type JobStates = {
6
- created : 'created',
6
+ created: 'created',
7
7
  retry: 'retry',
8
8
  active: 'active',
9
9
  completed: 'completed',
@@ -17,7 +17,7 @@ declare namespace PgBoss {
17
17
  singleton: 'singleton',
18
18
  stately: 'stately'
19
19
  }
20
-
20
+
21
21
  interface Db {
22
22
  executeSql(text: string, values: any[]): Promise<{ rows: any[] }>;
23
23
  }
@@ -59,7 +59,7 @@ declare namespace PgBoss {
59
59
  interface QueueOptions {
60
60
  expireInSeconds?: number;
61
61
  retentionSeconds?: number;
62
- deleteAfterSeconds?: number;
62
+ deleteAfterSeconds?: number;
63
63
  retryLimit?: number;
64
64
  retryDelay?: number;
65
65
  retryBackoff?: boolean;
@@ -79,9 +79,9 @@ declare namespace PgBoss {
79
79
  db?: Db;
80
80
  }
81
81
 
82
- type InsertOptions = ConnectionOptions;
82
+ type InsertOptions = ConnectionOptions
83
83
 
84
- type SendOptions = JobOptions & QueueOptions & ConnectionOptions;
84
+ type SendOptions = JobOptions & QueueOptions & ConnectionOptions
85
85
 
86
86
  type QueuePolicy = 'standard' | 'short' | 'singleton' | 'stately'
87
87
 
@@ -97,7 +97,7 @@ declare namespace PgBoss {
97
97
  deferredCount: number;
98
98
  queuedCount: number;
99
99
  activeCount: number;
100
- completedCount: number;
100
+ totalCount: number
101
101
  table: number;
102
102
  createdOn: Date;
103
103
  updatedOn: Date;
@@ -117,7 +117,7 @@ declare namespace PgBoss {
117
117
  }
118
118
 
119
119
  type WorkOptions = JobFetchOptions & JobPollingOptions
120
- type FetchOptions = JobFetchOptions & ConnectionOptions;
120
+ type FetchOptions = JobFetchOptions & ConnectionOptions
121
121
 
122
122
  interface WorkHandler<ReqData> {
123
123
  (job: PgBoss.Job<ReqData>[]): Promise<any>;
@@ -184,8 +184,8 @@ declare namespace PgBoss {
184
184
  singletonKey?: string;
185
185
  singletonSeconds?: number;
186
186
  expireInSeconds?: number;
187
- deleteAfterSeconds: number;
188
- keepUntil?: Date | string;
187
+ deleteAfterSeconds?: number;
188
+ retentionSeconds?: number;
189
189
  }
190
190
 
191
191
  interface Worker {
@@ -217,102 +217,107 @@ declare namespace PgBoss {
217
217
  }
218
218
 
219
219
  declare class PgBoss extends EventEmitter {
220
- constructor(connectionString: string);
221
- constructor(options: PgBoss.ConstructorOptions);
220
+ constructor (connectionString: string)
221
+ constructor (options: PgBoss.ConstructorOptions)
222
222
 
223
- static getConstructionPlans(schema?: string): string;
224
- static getMigrationPlans(schema?: string, version?: string): string;
225
- static getRollbackPlans(schema?: string, version?: string): string;
223
+ static getConstructionPlans (schema?: string): string
224
+ static getMigrationPlans (schema?: string, version?: string): string
225
+ static getRollbackPlans (schema?: string, version?: string): string
226
226
 
227
227
  static states: PgBoss.JobStates
228
228
  static policies: PgBoss.QueuePolicies
229
229
 
230
- on(event: "error", handler: (error: Error) => void): this;
231
- off(event: "error", handler: (error: Error) => void): this;
230
+ on (event: 'error', handler: (error: Error) => void): this
231
+ off (event: 'error', handler: (error: Error) => void): this
232
+
233
+ on (event: 'warning', handler: (warning: { message: string, data: object }) => void): this
234
+ off (event: 'warning', handler: (warning: { message: string, data: object }) => void): this
232
235
 
233
- on(event: "warning", handler: (warning: { message: string, data: object }) => void): this;
234
- off(event: "warning", handler: (warning: { message: string, data: object }) => void): this;
236
+ on (event: 'wip', handler: (data: PgBoss.Worker[]) => void): this
237
+ off (event: 'wip', handler: (data: PgBoss.Worker[]) => void): this
235
238
 
236
- on(event: "wip", handler: (data: PgBoss.Worker[]) => void): this;
237
- off(event: "wip", handler: (data: PgBoss.Worker[]) => void): this;
239
+ on (event: 'stopped', handler: () => void): this
240
+ off (event: 'stopped', handler: () => void): this
238
241
 
239
- start(): Promise<PgBoss>;
240
- stop(options?: PgBoss.StopOptions): Promise<void>;
242
+ start (): Promise<PgBoss>
243
+ stop (options?: PgBoss.StopOptions): Promise<void>
241
244
 
242
- send(request: PgBoss.Request): Promise<string | null>;
243
- send(name: string, data: object): Promise<string | null>;
244
- send(name: string, data: object, options: PgBoss.SendOptions): Promise<string | null>;
245
+ send (request: PgBoss.Request): Promise<string | null>
246
+ send (name: string, data: object): Promise<string | null>
247
+ send (name: string, data: object, options: PgBoss.SendOptions): Promise<string | null>
245
248
 
246
- sendAfter(name: string, data: object, options: PgBoss.SendOptions, date: Date): Promise<string | null>;
247
- sendAfter(name: string, data: object, options: PgBoss.SendOptions, dateString: string): Promise<string | null>;
248
- sendAfter(name: string, data: object, options: PgBoss.SendOptions, seconds: number): Promise<string | null>;
249
+ sendAfter (name: string, data: object, options: PgBoss.SendOptions, date: Date): Promise<string | null>
250
+ sendAfter (name: string, data: object, options: PgBoss.SendOptions, dateString: string): Promise<string | null>
251
+ sendAfter (name: string, data: object, options: PgBoss.SendOptions, seconds: number): Promise<string | null>
249
252
 
250
- sendThrottled(name: string, data: object, options: PgBoss.SendOptions, seconds: number, key?: string): Promise<string | null>;
251
- sendDebounced(name: string, data: object, options: PgBoss.SendOptions, seconds: number, key?: string): Promise<string | null>;
253
+ sendThrottled (name: string, data: object, options: PgBoss.SendOptions, seconds: number, key?: string): Promise<string | null>
254
+ sendDebounced (name: string, data: object, options: PgBoss.SendOptions, seconds: number, key?: string): Promise<string | null>
252
255
 
253
- insert(name: string, jobs: PgBoss.JobInsert[]): Promise<void>;
254
- insert(name: string, jobs: PgBoss.JobInsert[], options: PgBoss.InsertOptions): Promise<void>;
256
+ insert (name: string, jobs: PgBoss.JobInsert[]): Promise<void>
257
+ insert (name: string, jobs: PgBoss.JobInsert[], options: PgBoss.InsertOptions): Promise<void>
255
258
 
256
- fetch<T>(name: string): Promise<PgBoss.Job<T>[]>;
257
- fetch<T>(name: string, options: PgBoss.FetchOptions & { includeMetadata: true }): Promise<PgBoss.JobWithMetadata<T>[]>;
258
- fetch<T>(name: string, options: PgBoss.FetchOptions): Promise<PgBoss.Job<T>[]>;
259
+ fetch<T>(name: string): Promise<PgBoss.Job<T>[]>
260
+ fetch<T>(name: string, options: PgBoss.FetchOptions & { includeMetadata: true }): Promise<PgBoss.JobWithMetadata<T>[]>
261
+ fetch<T>(name: string, options: PgBoss.FetchOptions): Promise<PgBoss.Job<T>[]>
259
262
 
260
- work<ReqData>(name: string, handler: PgBoss.WorkHandler<ReqData>): Promise<string>;
261
- work<ReqData>(name: string, options: PgBoss.WorkOptions & { includeMetadata: true }, handler: PgBoss.WorkWithMetadataHandler<ReqData>): Promise<string>;
262
- work<ReqData>(name: string, options: PgBoss.WorkOptions, handler: PgBoss.WorkHandler<ReqData>): Promise<string>;
263
+ work<ReqData>(name: string, handler: PgBoss.WorkHandler<ReqData>): Promise<string>
264
+ work<ReqData>(name: string, options: PgBoss.WorkOptions & { includeMetadata: true }, handler: PgBoss.WorkWithMetadataHandler<ReqData>): Promise<string>
265
+ work<ReqData>(name: string, options: PgBoss.WorkOptions, handler: PgBoss.WorkHandler<ReqData>): Promise<string>
263
266
 
264
- offWork(name: string): Promise<void>;
265
- offWork(options: PgBoss.OffWorkOptions): Promise<void>;
267
+ offWork (name: string): Promise<void>
268
+ offWork (options: PgBoss.OffWorkOptions): Promise<void>
266
269
 
267
- notifyWorker(workerId: string): void;
270
+ notifyWorker (workerId: string): void
268
271
 
269
- subscribe(event: string, name: string): Promise<void>;
270
- unsubscribe(event: string, name: string): Promise<void>;
271
- publish(event: string): Promise<void>;
272
- publish(event: string, data: object): Promise<void>;
273
- publish(event: string, data: object, options: PgBoss.SendOptions): Promise<void>;
272
+ subscribe (event: string, name: string): Promise<void>
273
+ unsubscribe (event: string, name: string): Promise<void>
274
+ publish (event: string): Promise<void>
275
+ publish (event: string, data: object): Promise<void>
276
+ publish (event: string, data: object, options: PgBoss.SendOptions): Promise<void>
274
277
 
275
- cancel(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
276
- cancel(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
278
+ cancel (name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>
279
+ cancel (name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>
277
280
 
278
- resume(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
279
- resume(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
281
+ resume (name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>
282
+ resume (name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>
280
283
 
281
- retry(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
282
- retry(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
284
+ retry (name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>
285
+ retry (name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>
283
286
 
284
- deleteJob(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
285
- deleteJob(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
286
- deleteQueuedJobs(name: string): Promise<void>;
287
- deleteStoredJobs(name: string): Promise<void>;
288
- deleteAllJobs(name: string): Promise<void>;
287
+ deleteJob (name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>
288
+ deleteJob (name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>
289
+ deleteQueuedJobs (name: string): Promise<void>
290
+ deleteStoredJobs (name: string): Promise<void>
291
+ deleteAllJobs (name: string): Promise<void>
289
292
 
290
- complete(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
291
- complete(name: string, id: string, data: object, options?: PgBoss.ConnectionOptions): Promise<void>;
292
- complete(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
293
+ complete (name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>
294
+ complete (name: string, id: string, data: object, options?: PgBoss.ConnectionOptions): Promise<void>
295
+ complete (name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>
293
296
 
294
- fail(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
295
- fail(name: string, id: string, data: object, options?: PgBoss.ConnectionOptions): Promise<void>;
296
- fail(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
297
+ fail (name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>
298
+ fail (name: string, id: string, data: object, options?: PgBoss.ConnectionOptions): Promise<void>
299
+ fail (name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>
297
300
 
298
- getJobById<T>(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<PgBoss.JobWithMetadata<T> | null>;
301
+ getJobById<T>(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<PgBoss.JobWithMetadata<T> | null>
299
302
 
300
- createQueue(name: string, options?: PgBoss.Queue): Promise<void>;
301
- updateQueue(name: string, options?: PgBoss.Queue): Promise<void>;
302
- deleteQueue(name: string): Promise<void>;
303
- getQueues(): Promise<PgBoss.QueueResult[]>;
304
- getQueue(name: string): Promise<PgBoss.QueueResult | null>;
305
- getQueueStats(name: string): Promise<number>;
303
+ createQueue (name: string, options?: Omit<PgBoss.Queue, 'name'>): Promise<void>
304
+ createQueue (options: PgBoss.Queue): Promise<void>
305
+ updateQueue (name: string, options?: Omit<PgBoss.Queue, 'name'>): Promise<void>
306
+ updateQueue (options: PgBoss.Queue): Promise<void>
307
+ deleteQueue (name: string): Promise<void>
308
+ getQueues (): Promise<PgBoss.QueueResult[]>
309
+ getQueue (name: string): Promise<PgBoss.QueueResult | null>
310
+ getQueueStats (name: string): Promise<PgBoss.QueueResult>
306
311
 
307
- supervise(name?: string): Promise<void>;
308
- isInstalled(): Promise<Boolean>;
309
- schemaVersion(): Promise<Number>;
312
+ supervise (name?: string): Promise<void>
313
+ isInstalled (): Promise<boolean>
314
+ schemaVersion (): Promise<number>
310
315
 
311
- schedule(name: string, cron: string, data?: object, options?: PgBoss.ScheduleOptions): Promise<void>;
312
- unschedule(name: string, key?: string): Promise<void>;
313
- getSchedules(name?: string, key?: string): Promise<PgBoss.Schedule[]>;
316
+ schedule (name: string, cron: string, data?: object, options?: PgBoss.ScheduleOptions): Promise<void>
317
+ unschedule (name: string, key?: string): Promise<void>
318
+ getSchedules (name?: string, key?: string): Promise<PgBoss.Schedule[]>
314
319
 
315
- getDb(): PgBoss.Db;
320
+ getDb (): PgBoss.Db
316
321
  }
317
322
 
318
- export = PgBoss;
323
+ export = PgBoss