pg-boss 12.36.0 → 12.37.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.
- package/README.md +2 -2
- package/dist/attorney.d.ts.map +1 -1
- package/dist/attorney.js +5 -0
- package/dist/cli.js +8 -2
- package/dist/contractor.d.ts +1 -0
- package/dist/contractor.d.ts.map +1 -1
- package/dist/contractor.js +4 -0
- package/dist/db.js +3 -3
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -10
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +111 -13
- package/dist/migrationStore.d.ts.map +1 -1
- package/dist/migrationStore.js +127 -0
- package/dist/plans.d.ts +8 -2
- package/dist/plans.d.ts.map +1 -1
- package/dist/plans.js +90 -16
- package/dist/registrar.d.ts +1 -1
- package/dist/registrar.d.ts.map +1 -1
- package/dist/registrar.js +6 -1
- package/dist/schema.json +35 -2
- package/dist/timekeeper.d.ts +4 -1
- package/dist/timekeeper.d.ts.map +1 -1
- package/dist/timekeeper.js +22 -5
- package/dist/types.d.ts +12 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/worker.d.ts +1 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,9 +51,9 @@ This will likely cater the most to teams already familiar with the simplicity of
|
|
|
51
51
|
* Pub/sub API for fan-out queue relationships
|
|
52
52
|
* SQL support for non-Node.js runtimes for most operations
|
|
53
53
|
* Serverless function compatible
|
|
54
|
-
* [OpenTelemetry](https://pgboss.io/opentelemetry) traces and metrics
|
|
54
|
+
* [OpenTelemetry](https://pgboss.io/opentelemetry) traces and metrics
|
|
55
55
|
* Multi-master compatible (for example, in a Kubernetes ReplicaSet)
|
|
56
|
-
* [Additional database backends](https://pgboss.io/database-backends) for Postgres-based databases such as CockroachDB
|
|
56
|
+
* [Additional database backends](https://pgboss.io/database-backends) for Postgres-based databases such as CockroachDB and Citus. Or, use embedded PGlite for running entirely in-process.
|
|
57
57
|
|
|
58
58
|
## CLI
|
|
59
59
|
|
package/dist/attorney.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attorney.d.ts","sourceRoot":"","sources":["../src/attorney.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AAExC,QAAA,MAAM,MAAM;;;;CAIX,CAAA;AAKD,QAAA,MAAM,mBAAmB,6RAcf,CAAA;AA+EV,iBAAS,iBAAiB,CAAE,MAAM,GAAE,GAAQ,QAc3C;AAiBD,iBAAS,mBAAmB,CAAE,KAAK,EAAE,MAAM,UAE1C;AAED,iBAAS,aAAa,CAAE,IAAI,EAAE,GAAG,GAAG,KAAK,CAAC,OAAO,CAgDhD;AAOD,iBAAS,eAAe,CAAE,IAAI,EAAE,GAAG,EAAE,EAAE,MAAc,EAAE;;CAAK,GAAG,KAAK,CAAC,OAAO,CA4D3E;AAED,iBAAS,mBAAmB,CAAE,MAAM,EAAE,GAAG,QAOxC;AAED,iBAAS,gBAAgB,CAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,QA2D/C;AA2GD,iBAAS,aAAa,CAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG;IAClD,OAAO,EAAE,KAAK,CAAC,mBAAmB,CAAA;IAClC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;CACjC,CAgCA;AAqBD,iBAAS,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,QAQlD;AAED,iBAAS,SAAS,CAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC,0BAA0B,CA4B9F;
|
|
1
|
+
{"version":3,"file":"attorney.d.ts","sourceRoot":"","sources":["../src/attorney.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,KAAK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AClB,CAAA"}
|
package/dist/attorney.js
CHANGED
|
@@ -477,6 +477,11 @@ function resolveBackend(config) {
|
|
|
477
477
|
assert(backend in BACKEND_PROFILES, `configuration assert: backend must be one of ${Object.keys(BACKEND_PROFILES).join(', ')}`);
|
|
478
478
|
config.backend = backend;
|
|
479
479
|
const { flags } = BACKEND_PROFILES[backend];
|
|
480
|
+
// A DeprecationWarning, like the deprecated fetch options in manager.ts: dropping the profile is a
|
|
481
|
+
// configuration change a developer makes, not a condition an operator watches.
|
|
482
|
+
if (backend === 'yugabytedb') {
|
|
483
|
+
process.emitWarning("backend: 'yugabytedb' is deprecated and will be rejected in the next major. YugabyteDB is not supported: releases are not tested against it and upgrades do not work there. See https://pgboss.io/database-backends#not-supported-yugabytedb", 'DeprecationWarning', 'PGBOSS_DEP_YUGABYTEDB');
|
|
484
|
+
}
|
|
480
485
|
for (const flag of COMPATIBILITY_FLAGS) {
|
|
481
486
|
config[flag] = flags[flag] ?? false;
|
|
482
487
|
}
|
package/dist/cli.js
CHANGED
|
@@ -35,7 +35,7 @@ Options:
|
|
|
35
35
|
--password, -p <pass> Database password
|
|
36
36
|
--connection-string Full connection string (overrides other connection options)
|
|
37
37
|
--ssl Enable SSL connection
|
|
38
|
-
--backend <profile> Database backend: postgres (default), cockroachdb,
|
|
38
|
+
--backend <profile> Database backend: postgres (default), cockroachdb, citus.
|
|
39
39
|
Non-postgres backends need this to emit schema they accept.
|
|
40
40
|
--dry-run Output SQL without executing (for plans and reindex commands)
|
|
41
41
|
--force Rebuild every job index, not just the bloated ones (reindex)
|
|
@@ -69,6 +69,7 @@ Examples:
|
|
|
69
69
|
pg-boss migrate --schema my_schema
|
|
70
70
|
pg-boss create --connection-string postgres://user:pass@localhost/db
|
|
71
71
|
pg-boss plans migrate --dry-run
|
|
72
|
+
pg-boss plans uninstall --schema my_schema
|
|
72
73
|
pg-boss migrate --backend cockroachdb --connection-string postgres://root@localhost:26257/db
|
|
73
74
|
pg-boss version
|
|
74
75
|
PGBOSS_DATABASE_URL=postgres://localhost/mydb pg-boss migrate
|
|
@@ -708,9 +709,14 @@ async function cmdPlans(args) {
|
|
|
708
709
|
console.log(`-- SQL to rollback pg-boss from version ${schemaVersion} to ${schemaVersion - 1}:`);
|
|
709
710
|
console.log(migrationStore.rollback(schema, schemaVersion, migrationStore.getAllForConfig(config), config.noAdvisoryLocks));
|
|
710
711
|
break;
|
|
712
|
+
case 'uninstall':
|
|
713
|
+
console.log('-- SQL to remove every pg-boss object from a schema it shares with other objects.');
|
|
714
|
+
console.log(`-- If pg-boss has the schema to itself, DROP SCHEMA ${schema} CASCADE does the same.`);
|
|
715
|
+
console.log(plans.uninstall(schema, !config.noTablePartitioning));
|
|
716
|
+
break;
|
|
711
717
|
default:
|
|
712
718
|
console.error(`Unknown plans subcommand: ${subCommand}`);
|
|
713
|
-
console.error('Available: create, migrate, rollback');
|
|
719
|
+
console.error('Available: create, migrate, rollback, uninstall');
|
|
714
720
|
process.exit(1);
|
|
715
721
|
}
|
|
716
722
|
}
|
package/dist/contractor.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare function installConfig<T extends {
|
|
|
5
5
|
declare class Contractor {
|
|
6
6
|
static constructionPlans(schema?: string, options?: types.ConstructionPlanOptions): string;
|
|
7
7
|
static migrationPlans(schema?: string, version?: number, options?: types.MigrationPlanOptions): string;
|
|
8
|
+
static uninstallPlans(schema?: string, options?: types.PlanOptions): string;
|
|
8
9
|
static rollbackPlans(schema?: string, version?: number, options?: types.PlanOptions): string;
|
|
9
10
|
private config;
|
|
10
11
|
private db;
|
package/dist/contractor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractor.d.ts","sourceRoot":"","sources":["../src/contractor.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AAsBxC,wBAAsB,aAAa,CAAC,CAAC,SAAS;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,EAA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K,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO3H;AAED,cAAM,UAAU;IACd,MAAM,CAAC,iBAAiB,CAAE,MAAM,SAAuB,EAAE,OAAO,GAAE,KAAK,CAAC,uBAA4B;IAcpG,MAAM,CAAC,cAAc,CAAE,MAAM,SAAuB,EAAE,OAAO,SAAoB,EAAE,OAAO,GAAE,KAAK,CAAC,oBAAyB;IAS3H,MAAM,CAAC,cAAc,CAAE,MAAM,SAAuB,EAAE,OAAO,GAAE,KAAK,CAAC,WAAgB;IAMrF,MAAM,CAAC,aAAa,CAAE,MAAM,SAAuB,EAAE,OAAO,SAAgB,EAAE,OAAO,GAAE,KAAK,CAAC,WAAgB;IAM7G,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,UAAU,CAAmB;gBAExB,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,0BAA0B;IAgBpE,aAAa;IAKb,WAAW;IAKX,KAAK;YAsBG,yBAAyB;IAkCjC,WAAW,CAAE,OAAO,GAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC;IAwHzF,mBAAmB,IAAK,OAAO,CAAC,OAAO,CAAC;IASxC,oBAAoB,IAAK,OAAO,CAAC,IAAI,CAAC;IAItC,KAAK;IAcL,MAAM;IASN,OAAO,CAAE,OAAO,EAAE,MAAM;IASxB,IAAI,CAAE,OAAO,EAAE,MAAM;IAKrB,QAAQ,CAAE,OAAO,EAAE,MAAM;CAIhC;AAED,eAAe,UAAU,CAAA"}
|
package/dist/contractor.js
CHANGED
|
@@ -48,6 +48,10 @@ class Contractor {
|
|
|
48
48
|
// live connection can pass partition metadata to fan the builds out across partitions.
|
|
49
49
|
return migrationStore.migrate(schema, version, migrationStore.getAllForConfig(config), config.noAdvisoryLocks, { inlineAsync: true, partitionTables: options.partitionTables });
|
|
50
50
|
}
|
|
51
|
+
static uninstallPlans(schema = plans.DEFAULT_SCHEMA, options = {}) {
|
|
52
|
+
const config = planConfig(schema, options.backend);
|
|
53
|
+
return plans.uninstall(schema, !config.noTablePartitioning);
|
|
54
|
+
}
|
|
51
55
|
static rollbackPlans(schema = plans.DEFAULT_SCHEMA, version = schemaVersion, options = {}) {
|
|
52
56
|
const config = planConfig(schema, options.backend);
|
|
53
57
|
return migrationStore.rollback(schema, version, migrationStore.getAllForConfig(config), config.noAdvisoryLocks);
|
package/dist/db.js
CHANGED
|
@@ -97,7 +97,7 @@ class Db extends EventEmitter {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
async executeSql(text, values) {
|
|
100
|
-
assert(this.opened, 'Database not opened. Call
|
|
100
|
+
assert(this.opened, 'Database not opened. Call start() before using pg-boss, or again after stop().');
|
|
101
101
|
// if (this.config.debug === true) {
|
|
102
102
|
// console.log(`${new Date().toISOString()}: DEBUG SQL`)
|
|
103
103
|
// console.log(text)
|
|
@@ -114,7 +114,7 @@ class Db extends EventEmitter {
|
|
|
114
114
|
// drops and lost subscriptions. The client reconnects with capped backoff, re-runs LISTEN,
|
|
115
115
|
// then calls onReconnect so the caller can recover missed messages.
|
|
116
116
|
async listen(channel, onNotification, onReconnect) {
|
|
117
|
-
assert(this.opened, 'Database not opened. Call
|
|
117
|
+
assert(this.opened, 'Database not opened. Call start() before using pg-boss, or again after stop().');
|
|
118
118
|
let closed = false;
|
|
119
119
|
let client = null;
|
|
120
120
|
let reconnectTimer = null;
|
|
@@ -256,7 +256,7 @@ class Db extends EventEmitter {
|
|
|
256
256
|
// to the next caller mid-transaction: a failed COMMIT, a connection that errors while checked
|
|
257
257
|
// out, and a ROLLBACK that cannot get through.
|
|
258
258
|
async beginTransaction() {
|
|
259
|
-
assert(this.opened, 'Database not opened. Call
|
|
259
|
+
assert(this.opened, 'Database not opened. Call start() before using pg-boss, or again after stop().');
|
|
260
260
|
const client = await this.pool.connect();
|
|
261
261
|
let released = false;
|
|
262
262
|
// Why the connection died, when it died on its own rather than through commit() or rollback().
|
package/dist/index.d.ts
CHANGED
|
@@ -17,11 +17,17 @@ export declare function getMigrationPlans(schema?: string, version?: number, opt
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function getIndexBloatPlans(schema?: string, options?: types.IndexBloatOptions): string;
|
|
19
19
|
export declare function getRollbackPlans(schema?: string, version?: number, options?: types.PlanOptions): string;
|
|
20
|
+
/**
|
|
21
|
+
* The SQL that removes every object pg-boss installs, for a schema it shares with other objects. A
|
|
22
|
+
* schema of pg-boss's own is simpler to drop whole.
|
|
23
|
+
* @see https://pgboss.io/api/utils#getuninstallplans-schema-options
|
|
24
|
+
*/
|
|
25
|
+
export declare function getUninstallPlans(schema?: string, options?: types.PlanOptions): string;
|
|
20
26
|
export declare class PgBoss extends EventEmitter<types.PgBossEventMap> {
|
|
21
27
|
#private;
|
|
22
28
|
constructor(connectionString: string);
|
|
23
29
|
constructor(options: types.ConstructorOptions);
|
|
24
|
-
start(): Promise<this>;
|
|
30
|
+
start(options?: types.StartOptions): Promise<this>;
|
|
25
31
|
stop(options?: types.StopOptions): Promise<void>;
|
|
26
32
|
send(request: types.Request): Promise<string | null>;
|
|
27
33
|
send(name: string, data?: object | null, options?: types.SendOptions): Promise<string | null>;
|
|
@@ -105,7 +111,7 @@ export declare class PgBoss extends EventEmitter<types.PgBossEventMap> {
|
|
|
105
111
|
* such as `FREQ=MONTHLY;BYDAY=-1FR;BYHOUR=17`.
|
|
106
112
|
*/
|
|
107
113
|
schedule(name: string, cron: string, data?: object | null, options?: types.ScheduleOptions): Promise<void>;
|
|
108
|
-
unschedule(name: string, key?: string): Promise<void>;
|
|
114
|
+
unschedule(name: string, key?: string, options?: types.ConnectionOptions): Promise<void>;
|
|
109
115
|
getSchedules(name?: string, key?: string): Promise<types.Schedule[]>;
|
|
110
116
|
getSchedule(name: string, key?: string): Promise<types.Schedule | null>;
|
|
111
117
|
previewSchedule(cron: string, options?: types.PreviewScheduleOptions): Date[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,MAAM,aAAa,CAAA;AAatC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AAGxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,cAAc,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,cAAc,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,wBAAwB,IAAI,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAC/E,OAAO,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAElD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,MAOzB,CAAA;AAEF,wBAAgB,oBAAoB,CAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,uBAAuB,UAE7F;AAED,wBAAgB,iBAAiB,CAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,oBAAoB,UAEzG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,iBAAiB,UAErF;AAED,wBAAgB,gBAAgB,CAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,WAAW,UAE/F;AAED,qB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EAChB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,cAAc,EACd,OAAO,EACP,OAAO,EACP,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,WAAW,EACX,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,WAAW,EACX,MAAM,GACP,MAAM,UAAU,CAAA;AAEjB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,GACX,MAAM,qBAAqB,CAAA;AAE5B,YAAY,EACV,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,UAAU,EACV,UAAU,EACV,kBAAkB,GACnB,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert, { AssertionError } from 'node:assert';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import EventEmitter from 'node:events';
|
|
4
4
|
import * as Attorney from "./attorney.js";
|
|
@@ -46,10 +46,22 @@ export function getIndexBloatPlans(schema, options) {
|
|
|
46
46
|
export function getRollbackPlans(schema, version, options) {
|
|
47
47
|
return Contractor.rollbackPlans(schema, version, options);
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The SQL that removes every object pg-boss installs, for a schema it shares with other objects. A
|
|
51
|
+
* schema of pg-boss's own is simpler to drop whole.
|
|
52
|
+
* @see https://pgboss.io/api/utils#getuninstallplans-schema-options
|
|
53
|
+
*/
|
|
54
|
+
export function getUninstallPlans(schema, options) {
|
|
55
|
+
return Contractor.uninstallPlans(schema, options);
|
|
56
|
+
}
|
|
57
|
+
// start({ attempts }) waits 1 second after the first failure and doubles the wait up to this.
|
|
58
|
+
const START_RETRY_MAX_SECONDS = 30;
|
|
49
59
|
export class PgBoss extends EventEmitter {
|
|
50
60
|
#stopped;
|
|
51
61
|
#started;
|
|
52
62
|
#startingPromise = null;
|
|
63
|
+
// The wait between start() attempts, so stop() can end it rather than sit out every retry.
|
|
64
|
+
#startRetry = null;
|
|
53
65
|
#stoppingPromise = null;
|
|
54
66
|
#attachedClock = null;
|
|
55
67
|
#idle;
|
|
@@ -117,7 +129,9 @@ export class PgBoss extends EventEmitter {
|
|
|
117
129
|
emitter.on(event, arg => this.emit(event, arg));
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
|
-
async start() {
|
|
132
|
+
async start(options = {}) {
|
|
133
|
+
const { attempts = 1 } = options;
|
|
134
|
+
assert(Number.isInteger(attempts) && attempts >= 1, 'start() attempts must be an integer of 1 or more');
|
|
121
135
|
// A stop() already in flight must finish (clearing any resources it's tearing down) before a
|
|
122
136
|
// fresh start() begins, otherwise the two race over the same intervals/pool.
|
|
123
137
|
if (this.#stoppingPromise) {
|
|
@@ -136,7 +150,7 @@ export class PgBoss extends EventEmitter {
|
|
|
136
150
|
// partway through, subsystems already started (e.g. manager's queueCacheInterval/wipInterval)
|
|
137
151
|
// must still be reachable by stop() for cleanup, and stop() no-ops whenever #stopped is true.
|
|
138
152
|
this.#stopped = false;
|
|
139
|
-
this.#startingPromise = this.#
|
|
153
|
+
this.#startingPromise = this.#startAttempts(attempts);
|
|
140
154
|
try {
|
|
141
155
|
return await this.#startingPromise;
|
|
142
156
|
}
|
|
@@ -144,7 +158,44 @@ export class PgBoss extends EventEmitter {
|
|
|
144
158
|
this.#startingPromise = null;
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
|
-
|
|
161
|
+
// Each attempt is the same as calling start() again after a failure, which is safe on the same
|
|
162
|
+
// instance. An AssertionError is pg-boss refusing a configuration it cannot run, which fails the
|
|
163
|
+
// same way every time, so it is thrown at once. Anything else, a database not up yet or a schema
|
|
164
|
+
// another process is still migrating, gets the remaining attempts.
|
|
165
|
+
async #startAttempts(attempts) {
|
|
166
|
+
const retry = { cancelled: false, wait: null };
|
|
167
|
+
this.#startRetry = retry;
|
|
168
|
+
try {
|
|
169
|
+
for (let attempt = 1;; attempt++) {
|
|
170
|
+
try {
|
|
171
|
+
return await this.#doStart(attempt);
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
if (attempt >= attempts || retry.cancelled || err instanceof AssertionError) {
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
const delaySeconds = Math.min(2 ** (attempt - 1), START_RETRY_MAX_SECONDS);
|
|
178
|
+
// Once per start(), on the first failure: an outage would otherwise repeat it every try.
|
|
179
|
+
if (attempt === 1) {
|
|
180
|
+
this.emit(events.warning, {
|
|
181
|
+
message: `start() failed and will try again, up to ${attempts - 1} more times: ${err?.message}`,
|
|
182
|
+
data: { type: 'start_retry', attempts, error: err?.message }
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
retry.wait = delay(delaySeconds * 1000);
|
|
186
|
+
await retry.wait;
|
|
187
|
+
retry.wait = null;
|
|
188
|
+
if (retry.cancelled) {
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
this.#startRetry = null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async #doStart(attempt = 1) {
|
|
148
199
|
// Before anything opens a connection or runs a statement. The schema clock is gated on a
|
|
149
200
|
// session setting, and a session that misses it reads real time while its peers read fake
|
|
150
201
|
// time - silently, and differently on every checkout. Declaring the setup here means no
|
|
@@ -179,7 +230,7 @@ export class PgBoss extends EventEmitter {
|
|
|
179
230
|
if (this.#config.migrate) {
|
|
180
231
|
await this.#bam.start();
|
|
181
232
|
}
|
|
182
|
-
await this.#registrar.start();
|
|
233
|
+
await this.#registrar.start(attempt);
|
|
183
234
|
this.#started = true;
|
|
184
235
|
return this;
|
|
185
236
|
}
|
|
@@ -194,7 +245,7 @@ export class PgBoss extends EventEmitter {
|
|
|
194
245
|
if (/yugabyte|-yb-/i.test(version)) {
|
|
195
246
|
if (!this.#config.noTablePartitioning || !this.#config.noAdvisoryLocks) {
|
|
196
247
|
this.emit(events.warning, {
|
|
197
|
-
message: "YugabyteDB detected
|
|
248
|
+
message: "YugabyteDB detected. YugabyteDB is not supported. Until the next major, backend: 'yugabytedb' avoids the table partitioning and advisory locks that fail there.",
|
|
198
249
|
data: { backend: 'yugabytedb' }
|
|
199
250
|
});
|
|
200
251
|
}
|
|
@@ -206,7 +257,12 @@ export class PgBoss extends EventEmitter {
|
|
|
206
257
|
}
|
|
207
258
|
async stop(options = {}) {
|
|
208
259
|
// A start() already in flight must finish (or fail) before stop() evaluates state, otherwise
|
|
209
|
-
// stop() reads #stopped mid-start and silently no-ops while start() keeps running.
|
|
260
|
+
// stop() reads #stopped mid-start and silently no-ops while start() keeps running. One waiting
|
|
261
|
+
// between attempts stops trying, so it fails now with its last error.
|
|
262
|
+
if (this.#startRetry) {
|
|
263
|
+
this.#startRetry.cancelled = true;
|
|
264
|
+
this.#startRetry.wait?.abort();
|
|
265
|
+
}
|
|
210
266
|
if (this.#startingPromise) {
|
|
211
267
|
await this.#startingPromise.catch(() => { });
|
|
212
268
|
}
|
|
@@ -248,6 +304,9 @@ export class PgBoss extends EventEmitter {
|
|
|
248
304
|
await this.#bam.stop();
|
|
249
305
|
const shutdown = async () => {
|
|
250
306
|
await this.#manager.failWip();
|
|
307
|
+
// Pending claims may not have reached worker.jobs when failWip ran. Drain their refusal
|
|
308
|
+
// before closing the pool or publishing stopped.
|
|
309
|
+
await this.#manager.settleCleanups();
|
|
251
310
|
// After the drain, so a graceful stop reads as live until its workers have finished.
|
|
252
311
|
await this.#registrar.stop();
|
|
253
312
|
const attachment = this.#attachedClock;
|
|
@@ -278,7 +337,7 @@ export class PgBoss extends EventEmitter {
|
|
|
278
337
|
await shutdown();
|
|
279
338
|
return;
|
|
280
339
|
}
|
|
281
|
-
// Real time, not the configured clock: the deadline bounds
|
|
340
|
+
// Real time, not the configured clock: the deadline bounds active-handler grace, and under a test
|
|
282
341
|
// clock nothing would tick it while the test is blocked inside stop().
|
|
283
342
|
let deadlineTimer;
|
|
284
343
|
const deadline = new Promise(resolve => { deadlineTimer = setTimeout(resolve, timeout); });
|
|
@@ -479,8 +538,8 @@ export class PgBoss extends EventEmitter {
|
|
|
479
538
|
schedule(name, cron, data, options) {
|
|
480
539
|
return this.#timekeeper.schedule(name, cron, data, options);
|
|
481
540
|
}
|
|
482
|
-
unschedule(name, key) {
|
|
483
|
-
return this.#timekeeper.unschedule(name, key);
|
|
541
|
+
unschedule(name, key, options) {
|
|
542
|
+
return this.#timekeeper.unschedule(name, key, options);
|
|
484
543
|
}
|
|
485
544
|
getSchedules(name, key) {
|
|
486
545
|
return this.#timekeeper.getSchedules(name, key);
|
package/dist/manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,MAAM,aAAa,CAAA;AAItC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAGzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAG7C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAU,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,MAAM,aAAa,CAAA;AAItC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAGzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAG7C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACn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aAAa,CAAE,IAAI,CAAC,EAAE,MAAM;IA8B5B,aAAa,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,KAAK,CAAC,iBAAsB,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;IAwJhG,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,KAAK,CAAC,iBAAsB,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAkBxH,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,KAAK,CAAC,eAAoB,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IAyCnG,eAAe,CAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,KAAK,CAAC,iBAAsB,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;IAQjH,aAAa,CAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,KAAK,CAAC,iBAAsB,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;IAQrH,OAAO,CAAC,QAAQ;CAWjB;AAED,eAAe,OAAO,CAAA"}
|
package/dist/manager.js
CHANGED
|
@@ -8,7 +8,7 @@ import { TRANSACTION_ROLLBACK_TIMEOUT_MS } from "./db.js";
|
|
|
8
8
|
import * as plans from "./plans.js";
|
|
9
9
|
import { percentile } from "./latency.js";
|
|
10
10
|
import * as timekeeper from "./timekeeper.js";
|
|
11
|
-
import { resolveWithinSeconds } from "./tools.js";
|
|
11
|
+
import { delay, resolveWithinSeconds } from "./tools.js";
|
|
12
12
|
import * as types from "./types.js";
|
|
13
13
|
import Worker from "./worker.js";
|
|
14
14
|
import { JobSpy } from "./spy.js";
|
|
@@ -16,6 +16,14 @@ import Telemetry, {} from "./telemetry.js";
|
|
|
16
16
|
const INTERNAL_QUEUES = Object.values(timekeeper.QUEUES).reduce((acc, i) => ({ ...acc, [i]: i }), {});
|
|
17
17
|
// postgres: current transaction is aborted, commands ignored until end of transaction block
|
|
18
18
|
const TRANSACTION_ABORTED = '25P02';
|
|
19
|
+
// serialization_failure, which CockroachDB raises for a transaction it has to restart.
|
|
20
|
+
const SERIALIZATION_FAILURE = '40001';
|
|
21
|
+
const UPSERT_ATTEMPTS = 3;
|
|
22
|
+
const QUEUE_NOT_FOUND = 'PGBOSS_QUEUE_NOT_FOUND';
|
|
23
|
+
// How long deleteQueue() keeps trying for the locks a queue with its own table needs: 25 ms doubling
|
|
24
|
+
// to 400 ms between tries, about 3 seconds in all.
|
|
25
|
+
const DELETE_QUEUE_ATTEMPTS = 12;
|
|
26
|
+
const DELETE_QUEUE_MAX_DELAY_MS = 400;
|
|
19
27
|
// pg's own default when the pool size is not configured. Used to tell a transactional worker how
|
|
20
28
|
// much room it actually has, since each handler in flight holds a connection of its own.
|
|
21
29
|
const DEFAULT_POOL_MAX = 10;
|
|
@@ -157,6 +165,16 @@ function rethrowWriteError(err) {
|
|
|
157
165
|
}
|
|
158
166
|
throw err;
|
|
159
167
|
}
|
|
168
|
+
// The foreign key a job insert broke, from the error's constraint field where the driver reports one
|
|
169
|
+
// and from the message otherwise, and the key value it could not find. Bun.SQL carries the SQLSTATE
|
|
170
|
+
// in errno.
|
|
171
|
+
function brokenForeignKey(err) {
|
|
172
|
+
if (err?.code !== plans.PG_ERROR.foreignKeyViolation && err?.errno !== plans.PG_ERROR.foreignKeyViolation)
|
|
173
|
+
return;
|
|
174
|
+
const constraint = err.constraint ?? err.constraint_name ?? /foreign key constraint "(\w+)"/.exec(err.message)?.[1];
|
|
175
|
+
const value = /\)=\('?(.*?)'?\) is not present/.exec(err.detail ?? err.message)?.[1];
|
|
176
|
+
return { constraint, value };
|
|
177
|
+
}
|
|
160
178
|
// For a json value read back from a row and bound again behind `::text::jsonb`. Null stays SQL NULL.
|
|
161
179
|
function toJsonText(value) {
|
|
162
180
|
return value == null ? null : JSON.stringify(value);
|
|
@@ -628,6 +646,10 @@ class Manager extends EventEmitter {
|
|
|
628
646
|
await this.#applyTransactionTimeout(transaction, timeoutGuc, timeoutMs);
|
|
629
647
|
}
|
|
630
648
|
}
|
|
649
|
+
// A fetch or transaction begin can finish after stop() has exhausted its active-handler grace.
|
|
650
|
+
if (worker?.graceExpired) {
|
|
651
|
+
throw new Error('pg-boss shut down before the handler started');
|
|
652
|
+
}
|
|
631
653
|
const handling = transaction
|
|
632
654
|
? callback(jobs, untracked(transaction.db))
|
|
633
655
|
: callback(jobs);
|
|
@@ -889,7 +911,7 @@ class Manager extends EventEmitter {
|
|
|
889
911
|
}
|
|
890
912
|
queue = await this.getQueue(name);
|
|
891
913
|
if (!queue) {
|
|
892
|
-
throw new Error(`Queue ${name} does not exist`);
|
|
914
|
+
throw Object.assign(new Error(`Queue ${name} does not exist`), { code: QUEUE_NOT_FOUND });
|
|
893
915
|
}
|
|
894
916
|
this.queues[name] = queue;
|
|
895
917
|
return queue;
|
|
@@ -898,6 +920,42 @@ class Manager extends EventEmitter {
|
|
|
898
920
|
if (this.queues)
|
|
899
921
|
delete this.queues[name];
|
|
900
922
|
}
|
|
923
|
+
// A job insert is what notices a queue deleted after this instance cached it: q_fkey fails for a
|
|
924
|
+
// queue in the shared table, and a queue with its own table (partition: true) fails on the dropped
|
|
925
|
+
// table (42P01), dlq_fkey for its dead letter queue. Each is rewritten into the error a missing
|
|
926
|
+
// queue gets up front, and a missing queue loses its cache entry so the next call fails before
|
|
927
|
+
// reaching the database. `names` are the queues the statement wrote to.
|
|
928
|
+
async #rethrowInsertError(err, names, owned) {
|
|
929
|
+
const broken = brokenForeignKey(err);
|
|
930
|
+
if (broken?.constraint === 'q_fkey') {
|
|
931
|
+
this.#throwQueueNotFound(broken.value && names.includes(broken.value) ? [broken.value] : names, err, owned);
|
|
932
|
+
}
|
|
933
|
+
// A missing table can also mean a queue deleted and created again elsewhere under its own table, and
|
|
934
|
+
// a partition constraint (23514) one created again with its own table while this instance still
|
|
935
|
+
// writes to the shared one. So the queues are read again: a gone one is reported as missing, and the
|
|
936
|
+
// others take their current row, so the next call writes to the right table. A failed read leaves
|
|
937
|
+
// the original error.
|
|
938
|
+
if (err?.code === plans.PG_ERROR.undefinedTable || err?.code === plans.PG_ERROR.checkViolation) {
|
|
939
|
+
const queues = await Promise.all(names.map(name => this.getQueue(name))).catch(() => null);
|
|
940
|
+
if (queues) {
|
|
941
|
+
const missing = names.filter((name, i) => !queues[i]);
|
|
942
|
+
if (missing.length)
|
|
943
|
+
this.#throwQueueNotFound(missing, err, owned);
|
|
944
|
+
queues.forEach(queue => { if (queue && this.queues)
|
|
945
|
+
this.queues[queue.name] = queue; });
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (broken?.constraint === 'dlq_fkey') {
|
|
949
|
+
throw new Error(broken.value ? `Dead letter queue ${broken.value} does not exist` : 'Dead letter queue does not exist', { cause: err });
|
|
950
|
+
}
|
|
951
|
+
rethrowWriteError(err);
|
|
952
|
+
}
|
|
953
|
+
// Coded, so publish() skips it, only when the statement ran on pg-boss's own connection: a failed
|
|
954
|
+
// statement in a caller's transaction has aborted it, and that has to reach the caller.
|
|
955
|
+
#throwQueueNotFound(missing, cause, owned) {
|
|
956
|
+
missing.forEach(name => this.#evictQueueCache(name));
|
|
957
|
+
throw Object.assign(new Error(`Queue ${missing.join(', ')} does not exist`, { cause }), owned ? { code: QUEUE_NOT_FOUND } : {});
|
|
958
|
+
}
|
|
901
959
|
// Replaces a queue's cache entry with its row as it stands, rather than evicting it, so a queue
|
|
902
960
|
// created again or updated stays in the cache and the queue gauge while still picking up what
|
|
903
961
|
// changed: new options, or a table that changed under it (deleted and recreated elsewhere with
|
|
@@ -931,6 +989,11 @@ class Manager extends EventEmitter {
|
|
|
931
989
|
// `stopped` all wait on this, so every worker has to be reached even when one of them cannot be
|
|
932
990
|
// failed.
|
|
933
991
|
async failWip() {
|
|
992
|
+
// Every worker is marked before any fail below is awaited, so a claim landing on a later worker
|
|
993
|
+
// while an earlier one's fail is in flight is refused too.
|
|
994
|
+
for (const worker of this.workers.values()) {
|
|
995
|
+
worker.graceExpired = true;
|
|
996
|
+
}
|
|
934
997
|
for (const worker of this.workers.values()) {
|
|
935
998
|
const jobIds = worker.jobs.map(j => j.id);
|
|
936
999
|
if (jobIds.length) {
|
|
@@ -968,6 +1031,10 @@ class Manager extends EventEmitter {
|
|
|
968
1031
|
if (transactional) {
|
|
969
1032
|
assert(typeof this.db.beginTransaction === 'function', 'transactional workers require a database connection pg-boss can open a transaction on: the built-in pool, or a db adapter implementing beginTransaction');
|
|
970
1033
|
await this.#assertTransactionalHeartbeatSupported(name);
|
|
1034
|
+
// A stop() during that await has already looked for workers, and would not see this one.
|
|
1035
|
+
if (this.stopped) {
|
|
1036
|
+
throw new Error('Workers are disabled. pg-boss is stopped');
|
|
1037
|
+
}
|
|
971
1038
|
this.#warnOnTransactionalPoolHeadroom(localConcurrency);
|
|
972
1039
|
}
|
|
973
1040
|
if (localGroupConcurrency != null) {
|
|
@@ -1227,7 +1294,8 @@ class Manager extends EventEmitter {
|
|
|
1227
1294
|
const results = await Promise.allSettled(rows.map(({ name }) => this.send(name, data, options)));
|
|
1228
1295
|
const failures = results
|
|
1229
1296
|
.map((result, index) => ({ result, name: rows[index].name }))
|
|
1230
|
-
|
|
1297
|
+
// A deleted subscriber can still be in the selection, just as a cached send can insert no job.
|
|
1298
|
+
.filter((entry) => entry.result.status === 'rejected' && entry.result.reason?.code !== QUEUE_NOT_FOUND);
|
|
1231
1299
|
if (failures.length > 0) {
|
|
1232
1300
|
// Each entry names its own queue, so attribution doesn't depend on lining errors[] up with
|
|
1233
1301
|
// the queue order positionally, and survives two subscribers failing with identical text.
|
|
@@ -1300,7 +1368,8 @@ class Manager extends EventEmitter {
|
|
|
1300
1368
|
throw new Error(`${plans.QUEUE_POLICIES.key_strict_fifo} queues require a singletonKey`);
|
|
1301
1369
|
}
|
|
1302
1370
|
const sql = plans.insertJobs(this.config.schema, { table, name, returnId: true, notify: this.#notifyEnabled(notify) });
|
|
1303
|
-
const
|
|
1371
|
+
const insert = () => db.executeSql(sql, [JSON.stringify([job])]).catch(err => this.#rethrowInsertError(err, [name], !wrapper));
|
|
1372
|
+
const { rows: try1 } = await insert();
|
|
1304
1373
|
if (try1.length === 1) {
|
|
1305
1374
|
const jobId = try1[0].id;
|
|
1306
1375
|
if (this.config.__test__enableSpies) {
|
|
@@ -1315,7 +1384,7 @@ class Manager extends EventEmitter {
|
|
|
1315
1384
|
// delay starting by the offset to honor throttling config
|
|
1316
1385
|
job.startAfter = this.getDebounceStartAfter(singletonSeconds, this.timekeeper.clockSkew);
|
|
1317
1386
|
job.singletonOffset = singletonSeconds;
|
|
1318
|
-
const { rows: try2 } = await
|
|
1387
|
+
const { rows: try2 } = await insert();
|
|
1319
1388
|
if (try2.length === 1) {
|
|
1320
1389
|
const jobId = try2[0].id;
|
|
1321
1390
|
if (this.config.__test__enableSpies) {
|
|
@@ -1389,11 +1458,12 @@ class Manager extends EventEmitter {
|
|
|
1389
1458
|
}
|
|
1390
1459
|
const notifyEnabled = this.#notifyEnabled(notify);
|
|
1391
1460
|
const updateSql = plans.updateJob(this.config.schema, table, name, by, match, notifyEnabled);
|
|
1392
|
-
const insertSql = plans.insertJobs(this.config.schema, { table, name, returnId: true, notify: notifyEnabled });
|
|
1461
|
+
const insertSql = plans.insertJobs(this.config.schema, { table, name, returnId: true, notify: notifyEnabled, upsertByKey: by === 'singletonKey' });
|
|
1393
1462
|
const job = this.#toUpdatePayload(data, opts);
|
|
1394
1463
|
const updatePayload = JSON.stringify(job);
|
|
1395
1464
|
const insertPayload = JSON.stringify([{ ...job, __traceContext: traceContext }]);
|
|
1396
|
-
|
|
1465
|
+
// The catch is outside the transaction: a deferred q_fkey reports at its COMMIT.
|
|
1466
|
+
const attempt = () => this.ensureTransaction(db, async (tx) => {
|
|
1397
1467
|
const { rows: updated } = await tx.executeSql(updateSql, [updatePayload]);
|
|
1398
1468
|
if (updated.length) {
|
|
1399
1469
|
const jobs = updated.map(row => row.id);
|
|
@@ -1409,7 +1479,22 @@ class Manager extends EventEmitter {
|
|
|
1409
1479
|
const { rows: retry } = await tx.executeSql(updateSql, [updatePayload]);
|
|
1410
1480
|
const jobs = retry.map(row => row.id);
|
|
1411
1481
|
return { jobs, updated: jobs.length, inserted: 0 };
|
|
1412
|
-
});
|
|
1482
|
+
}).catch(err => this.#rethrowInsertError(err, [name], !opts.db));
|
|
1483
|
+
// Where every transaction is serializable (CockroachDB), two upserts of one key that both miss
|
|
1484
|
+
// conflict and one fails with 40001, rather than waiting on job_i13 as under READ COMMITTED. The
|
|
1485
|
+
// transaction is pg-boss's own unless the caller passed a db, so the upsert runs again and finds
|
|
1486
|
+
// the other's job. A caller's transaction is theirs to retry.
|
|
1487
|
+
let result;
|
|
1488
|
+
for (let attempts = 1;; attempts++) {
|
|
1489
|
+
try {
|
|
1490
|
+
result = await attempt();
|
|
1491
|
+
break;
|
|
1492
|
+
}
|
|
1493
|
+
catch (err) {
|
|
1494
|
+
if (opts.db || err?.code !== SERIALIZATION_FAILURE || attempts === UPSERT_ATTEMPTS)
|
|
1495
|
+
throw err;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1413
1498
|
// Track inserted (newly created) jobs for spies, matching createJob/insert. Runs after the
|
|
1414
1499
|
// transaction commits so a rolled-back insert never leaves a phantom spy entry.
|
|
1415
1500
|
if (result.inserted && this.config.__test__enableSpies) {
|
|
@@ -1498,7 +1583,7 @@ class Manager extends EventEmitter {
|
|
|
1498
1583
|
// Return IDs if spy is active for this queue (needed for job tracking)
|
|
1499
1584
|
const returnId = !!spy || !!options.returnId;
|
|
1500
1585
|
const sql = plans.insertJobs(this.config.schema, { table, name, returnId, notify: this.#notifyEnabled(notify), slots });
|
|
1501
|
-
const { rows } = await db.executeSql(sql, [JSON.stringify(insertPayload)]);
|
|
1586
|
+
const { rows } = await db.executeSql(sql, [JSON.stringify(insertPayload)]).catch(err => this.#rethrowInsertError(err, [name], !options.db));
|
|
1502
1587
|
if (rows.length) {
|
|
1503
1588
|
if (spy) {
|
|
1504
1589
|
// dataById is populated for every job when a spy is active
|
|
@@ -1603,7 +1688,7 @@ class Manager extends EventEmitter {
|
|
|
1603
1688
|
await db.executeSql(sql);
|
|
1604
1689
|
}
|
|
1605
1690
|
catch (err) {
|
|
1606
|
-
|
|
1691
|
+
await this.#rethrowInsertError(err, [...byQueue.keys()], !options.db);
|
|
1607
1692
|
}
|
|
1608
1693
|
return refToId;
|
|
1609
1694
|
}
|
|
@@ -2183,8 +2268,21 @@ class Manager extends EventEmitter {
|
|
|
2183
2268
|
catch {
|
|
2184
2269
|
return;
|
|
2185
2270
|
}
|
|
2186
|
-
const sql = plans.deleteQueue(this.config.schema, name, this.config.noAdvisoryLocks);
|
|
2187
|
-
|
|
2271
|
+
const sql = plans.deleteQueue(this.config.schema, name, this.config.noAdvisoryLocks, !this.config.noTablePartitioning);
|
|
2272
|
+
// Only a queue with its own table takes locks that can be busy, and only those are tried again.
|
|
2273
|
+
for (let attempt = 1;; attempt++) {
|
|
2274
|
+
try {
|
|
2275
|
+
await this.db.executeSql(sql);
|
|
2276
|
+
break;
|
|
2277
|
+
}
|
|
2278
|
+
catch (err) {
|
|
2279
|
+
if (err?.code !== plans.PG_ERROR.lockNotAvailable)
|
|
2280
|
+
throw err;
|
|
2281
|
+
if (attempt === DELETE_QUEUE_ATTEMPTS)
|
|
2282
|
+
throw new Error(`Queue ${name} was not deleted: its tables stayed locked through ${attempt} tries`, { cause: err });
|
|
2283
|
+
await delay(Math.min(25 * 2 ** (attempt - 1), DELETE_QUEUE_MAX_DELAY_MS) * (0.5 + Math.random() / 2));
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2188
2286
|
this.#evictQueueCache(name);
|
|
2189
2287
|
}
|
|
2190
2288
|
async deleteQueuedJobs(name) {
|
|
@@ -2416,7 +2514,7 @@ class Manager extends EventEmitter {
|
|
|
2416
2514
|
return options.db;
|
|
2417
2515
|
}
|
|
2418
2516
|
if (this.db._pgbdb) {
|
|
2419
|
-
assert(this.db.opened, 'Database
|
|
2517
|
+
assert(this.db.opened, 'Database not opened. Call start() before using pg-boss, or again after stop().');
|
|
2420
2518
|
}
|
|
2421
2519
|
return this.db;
|
|
2422
2520
|
}
|