pg-boss 11.1.0 → 11.1.2

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/README.md CHANGED
@@ -82,9 +82,9 @@ To run the test suite, linter and code coverage:
82
82
  npm run cover
83
83
  ```
84
84
 
85
- The test suite will try and create a new database named pgboss. The [config.json](https://github.com/timgit/pg-boss/test/config.json) file has the default credentials to connect to postgres.
85
+ The test suite will try and create a new database named pgboss. The [config.json](https://github.com/timgit/pg-boss/blob/master/test/config.json) file has the default credentials to connect to postgres.
86
86
 
87
- The [Docker Compose](https://github.com/timgit/pg-boss/docker-compose.yaml) file can be used to start a local postgres instance for testing:
87
+ The [Docker Compose](https://github.com/timgit/pg-boss/blob/master/docker-compose.yaml) file can be used to start a local postgres instance for testing:
88
88
 
89
89
  ```bash
90
90
  docker compose up
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-boss",
3
- "version": "11.1.0",
3
+ "version": "11.1.2",
4
4
  "description": "Queueing jobs in Postgres from Node.js like a boss",
5
5
  "main": "./src/index.js",
6
6
  "type": "commonjs",
package/src/boss.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const EventEmitter = require('node:events')
2
2
  const plans = require('./plans')
3
+ const { unwrapSQLResult } = require('./tools')
3
4
 
4
5
  const events = {
5
6
  error: 'error',
@@ -58,7 +59,7 @@ class Boss extends EventEmitter {
58
59
  async #executeSql (sql, values) {
59
60
  const started = Date.now()
60
61
 
61
- const result = await this.#db.executeSql(sql, values)
62
+ const result = unwrapSQLResult(await this.#db.executeSql(sql, values))
62
63
 
63
64
  const ended = Date.now()
64
65
 
@@ -130,10 +131,8 @@ class Boss extends EventEmitter {
130
131
  const queues = rows.map(q => q.name)
131
132
 
132
133
  const cacheStatsSql = plans.cacheQueueStats(this.#config.schema, table, queues)
133
- const results = await this.#executeSql(cacheStatsSql)
134
-
135
- const inter = results.flatMap(i => i.rows)
136
- const warnings = inter.filter(i => i.queuedCount > (i.warningQueueSize || WARNINGS.LARGE_QUEUE.size))
134
+ const { rows: rowsCacheStats } = await this.#executeSql(cacheStatsSql)
135
+ const warnings = rowsCacheStats.filter(i => i.queuedCount > (i.warningQueueSize || WARNINGS.LARGE_QUEUE.size))
137
136
 
138
137
  for (const warning of warnings) {
139
138
  this.emit(events.warning, { message: WARNINGS.LARGE_QUEUE.mesasge, data: warning })
package/src/timekeeper.js CHANGED
@@ -136,7 +136,7 @@ class Timekeeper extends EventEmitter {
136
136
 
137
137
  const scheduled = schedules
138
138
  .filter(i => this.shouldSendIt(i.cron, i.timezone))
139
- .map(({ name, data, options }) => ({ data: { name, data, options }, singletonKey: name, singletonSeconds: 60 }))
139
+ .map(({ name, key, data, options }) => ({ data: { name, data, options }, singletonKey: `${name}__${key}`, singletonSeconds: 60 }))
140
140
 
141
141
  if (scheduled.length > 0 && !this.stopped) {
142
142
  await this.manager.insert(QUEUES.SEND_IT, scheduled)
package/src/tools.js CHANGED
@@ -2,7 +2,22 @@ const { setTimeout } = require('node:timers/promises')
2
2
 
3
3
  module.exports = {
4
4
  delay,
5
- resolveWithinSeconds
5
+ resolveWithinSeconds,
6
+ unwrapSQLResult
7
+ }
8
+
9
+ /**
10
+ * When sql contains multiple queries, result is an array of objects with rows property
11
+ * This function unwraps the result into a single object with rows property
12
+ * @param {{rows: Array<Object>} | Array<{rows: Array<Object>}>} result
13
+ * @returns {{rows: Array<Object>}}
14
+ */
15
+ function unwrapSQLResult (result) {
16
+ if (result instanceof Array) {
17
+ return { rows: result.flatMap(i => i.rows) }
18
+ }
19
+
20
+ return result
6
21
  }
7
22
 
8
23
  function delay (ms, error) {
@@ -1,15 +0,0 @@
1
- services:
2
- db:
3
- image: postgres:18
4
- ports:
5
- - 5432:5432
6
- volumes:
7
- - db_volume:/var/lib/postgresql/data18
8
- environment:
9
- - POSTGRES_DB=pgboss
10
- - POSTGRES_NAME=pgboss
11
- - POSTGRES_USER=postgres
12
- - POSTGRES_PASSWORD=postgres
13
-
14
- volumes:
15
- db_volume: