pg-boss 7.0.3 → 7.1.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/package.json +1 -1
- package/src/index.js +8 -8
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -73,12 +73,14 @@ class PgBoss extends EventEmitter {
|
|
|
73
73
|
|
|
74
74
|
function promoteFunction (obj, func) {
|
|
75
75
|
this[func.name] = (...args) => {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const shouldRun = !this.started || !((func.name === 'work' || func.name === 'onComplete') && (this.stopped || this.stoppingOn))
|
|
77
|
+
|
|
78
|
+
if (shouldRun) {
|
|
79
|
+
return func.apply(obj, args)
|
|
80
|
+
} else {
|
|
81
|
+
const state = this.stoppingOn ? 'stopping' : this.stopped ? 'stopped' : !this.started ? 'not started' : 'started'
|
|
78
82
|
return Promise.reject(new Error(`pg-boss is ${state}.`))
|
|
79
83
|
}
|
|
80
|
-
|
|
81
|
-
return func.apply(obj, args)
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -100,6 +102,8 @@ class PgBoss extends EventEmitter {
|
|
|
100
102
|
|
|
101
103
|
await this.contractor.start()
|
|
102
104
|
|
|
105
|
+
this.started = true
|
|
106
|
+
|
|
103
107
|
this.manager.start()
|
|
104
108
|
|
|
105
109
|
if (!this.config.noSupervisor) {
|
|
@@ -132,10 +136,6 @@ class PgBoss extends EventEmitter {
|
|
|
132
136
|
await this.timekeeper.stop()
|
|
133
137
|
|
|
134
138
|
const shutdown = async () => {
|
|
135
|
-
if (this.db.isOurs) {
|
|
136
|
-
await this.db.close()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
139
|
this.stopped = true
|
|
140
140
|
this.stoppingOn = null
|
|
141
141
|
|