bullmq 6.3.8 → 6.3.10
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/dist/cjs/classes/flow-producer.js +4 -4
- package/dist/cjs/classes/queue-base.js +5 -13
- package/dist/cjs/classes/queue-events-producer.js +5 -5
- package/dist/cjs/classes/queue-events.js +7 -10
- package/dist/cjs/classes/queue.js +1 -1
- package/dist/cjs/classes/worker.js +12 -6
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/postgres/create-postgres-backend.js +3 -5
- package/dist/cjs/postgres/postgres-connection.js +4 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/types/default-queue-options.js +2 -0
- package/dist/cjs/types/no-infer.js +2 -0
- package/dist/cjs/types/queue-type.js +2 -0
- package/dist/cjs/utils/create-backend.js +26 -8
- package/dist/cjs/utils/with-backend.js +54 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/flow-producer.d.ts +8 -3
- package/dist/esm/classes/flow-producer.js +4 -4
- package/dist/esm/classes/job-scheduler.d.ts +6 -3
- package/dist/esm/classes/job.d.ts +16 -10
- package/dist/esm/classes/queue-base.d.ts +12 -6
- package/dist/esm/classes/queue-base.js +5 -13
- package/dist/esm/classes/queue-events-producer.d.ts +9 -3
- package/dist/esm/classes/queue-events-producer.js +5 -5
- package/dist/esm/classes/queue-events.d.ts +9 -3
- package/dist/esm/classes/queue-events.js +8 -11
- package/dist/esm/classes/queue-getters.d.ts +2 -1
- package/dist/esm/classes/queue.d.ts +11 -8
- package/dist/esm/classes/queue.js +1 -1
- package/dist/esm/classes/worker.d.ts +10 -5
- package/dist/esm/classes/worker.js +12 -6
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/interfaces/minimal-queue.d.ts +3 -2
- package/dist/esm/interfaces/queue-backend.d.ts +5 -5
- package/dist/esm/interfaces/queue-options.d.ts +12 -9
- package/dist/esm/interfaces/worker-options.d.ts +2 -1
- package/dist/esm/postgres/create-postgres-backend.d.ts +5 -6
- package/dist/esm/postgres/create-postgres-backend.js +3 -5
- package/dist/esm/postgres/pg-types.d.ts +1 -3
- package/dist/esm/postgres/postgres-connection.js +4 -1
- package/dist/esm/postgres/postgres-queue-backend.d.ts +3 -3
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/types/default-queue-options.d.ts +10 -0
- package/dist/esm/types/default-queue-options.js +1 -0
- package/dist/esm/types/no-infer.d.ts +5 -0
- package/dist/esm/types/no-infer.js +1 -0
- package/dist/esm/types/queue-type.d.ts +4 -0
- package/dist/esm/types/queue-type.js +1 -0
- package/dist/esm/utils/create-backend.d.ts +9 -5
- package/dist/esm/utils/create-backend.js +26 -8
- package/dist/esm/utils/with-backend.d.ts +36 -0
- package/dist/esm/utils/with-backend.js +51 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +13 -12
|
@@ -15,13 +15,13 @@ const enums_1 = require("../enums");
|
|
|
15
15
|
* All Jobs can be in different queues, either children or parents,
|
|
16
16
|
*/
|
|
17
17
|
class FlowProducer extends events_1.EventEmitter {
|
|
18
|
-
constructor(opts
|
|
18
|
+
constructor(opts, backendFactory) {
|
|
19
19
|
super();
|
|
20
|
-
this.opts = opts;
|
|
21
|
-
this.opts = Object.assign({}, opts);
|
|
20
|
+
this.opts = Object.assign(opts === undefined ? { connection: {} } : {}, opts);
|
|
22
21
|
// The flow producer is not bound to a single queue: each flow entry carries
|
|
23
22
|
// its own queue identity, so the backend is created with an empty name.
|
|
24
|
-
|
|
23
|
+
const factory = backendFactory !== null && backendFactory !== void 0 ? backendFactory : (0, create_backend_1.getDefaultBackendFactory)();
|
|
24
|
+
this.backend = factory('', this.opts);
|
|
25
25
|
this.backend.on('error', (error) => {
|
|
26
26
|
if (this.listenerCount('error') > 0) {
|
|
27
27
|
this.emit('error', error);
|
|
@@ -11,23 +11,15 @@ const job_1 = require("./job");
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
class QueueBase extends events_1.EventEmitter {
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @param name - The name of the queue.
|
|
17
|
-
* @param opts - Options for the queue.
|
|
18
|
-
* @param backendFactory - Factory used to build the {@link IQueueBackend}.
|
|
19
|
-
* Defaults to the Redis backend; inject a different factory to use another
|
|
20
|
-
* datastore or a test mock.
|
|
21
|
-
*/
|
|
22
|
-
constructor(name, opts = { connection: {} }, backendFactory = (0, create_backend_1.getDefaultBackendFactory)(), hasBlockingConnection = false) {
|
|
14
|
+
constructor(name, opts, backendFactory, hasBlockingConnection = false) {
|
|
23
15
|
super();
|
|
24
|
-
this.name = name;
|
|
25
|
-
this.opts = opts;
|
|
26
16
|
this.closed = false;
|
|
27
17
|
this.hasBlockingConnection = false;
|
|
28
|
-
this.
|
|
18
|
+
this.name = name;
|
|
19
|
+
this.backendFactory =
|
|
20
|
+
backendFactory !== null && backendFactory !== void 0 ? backendFactory : (0, create_backend_1.getDefaultBackendFactory)();
|
|
29
21
|
this.hasBlockingConnection = hasBlockingConnection;
|
|
30
|
-
this.opts = Object.assign({}, opts);
|
|
22
|
+
this.opts = Object.assign(opts === undefined ? { connection: {} } : {}, opts);
|
|
31
23
|
if (!name) {
|
|
32
24
|
throw new Error('Queue name must be provided');
|
|
33
25
|
}
|
|
@@ -7,11 +7,11 @@ const queue_base_1 = require("./queue-base");
|
|
|
7
7
|
* The QueueEventsProducer class is used for publishing custom events.
|
|
8
8
|
*/
|
|
9
9
|
class QueueEventsProducer extends queue_base_1.QueueBase {
|
|
10
|
-
constructor(name, opts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
constructor(name, opts, backendFactory) {
|
|
11
|
+
super(name, opts && Object.assign({ blockingConnection: false }, opts), backendFactory);
|
|
12
|
+
if (opts) {
|
|
13
|
+
this.opts = opts;
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Publish custom event to be processed in QueueEvents.
|
|
@@ -4,7 +4,6 @@ exports.QueueEvents = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const queue_base_1 = require("./queue-base");
|
|
7
|
-
const ioredis_client_1 = require("./ioredis-client");
|
|
8
7
|
/**
|
|
9
8
|
* The QueueEvents class is used for listening to the global events
|
|
10
9
|
* emitted by a given queue.
|
|
@@ -13,15 +12,13 @@ const ioredis_client_1 = require("./ioredis-client");
|
|
|
13
12
|
*
|
|
14
13
|
*/
|
|
15
14
|
class QueueEvents extends queue_base_1.QueueBase {
|
|
16
|
-
constructor(name,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
: (0, ioredis_client_1.createIORedisClient)(connection)).duplicate()
|
|
24
|
-
: connection }), backendFactory, true);
|
|
15
|
+
constructor(name, opts, backendFactory) {
|
|
16
|
+
const { autorun = true } = opts !== null && opts !== void 0 ? opts : {};
|
|
17
|
+
const queueOptions = opts && Object.assign({}, opts);
|
|
18
|
+
if (queueOptions) {
|
|
19
|
+
delete queueOptions.autorun;
|
|
20
|
+
}
|
|
21
|
+
super(name, queueOptions, backendFactory, true);
|
|
25
22
|
this.running = false;
|
|
26
23
|
this.blocking = false;
|
|
27
24
|
this.opts = Object.assign({
|
|
@@ -36,7 +36,7 @@ const utils_1 = require("../utils");
|
|
|
36
36
|
class Queue extends queue_getters_1.QueueGetters {
|
|
37
37
|
constructor(name, opts, backendFactory) {
|
|
38
38
|
var _a;
|
|
39
|
-
super(name,
|
|
39
|
+
super(name, opts, backendFactory);
|
|
40
40
|
this.token = (0, utils_1.randomUUID)();
|
|
41
41
|
this.libName = 'bullmq';
|
|
42
42
|
this.jobsOpts = (_a = opts === null || opts === void 0 ? void 0 : opts.defaultJobOptions) !== null && _a !== void 0 ? _a : {};
|
|
@@ -37,6 +37,9 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
37
37
|
return new errors_1.RateLimitError();
|
|
38
38
|
}
|
|
39
39
|
constructor(name, processor, opts, backendFactory) {
|
|
40
|
+
if (!opts || opts.connection === undefined || opts.connection === null) {
|
|
41
|
+
throw new Error('Worker requires a connection');
|
|
42
|
+
}
|
|
40
43
|
super(name, Object.assign(Object.assign({ drainDelay: 5, concurrency: 1, lockDuration: 30000, maximumRateLimitDelay: 30000, maxStalledCount: 1, stalledInterval: 30000, autorun: true, runRetryDelay: 15000 }, opts), { blockingConnection: true }), backendFactory);
|
|
41
44
|
this.abortDelayController = null;
|
|
42
45
|
this.blockUntil = 0;
|
|
@@ -47,9 +50,6 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
47
50
|
this.waiting = null;
|
|
48
51
|
this.running = false;
|
|
49
52
|
this.mainLoopRunning = null;
|
|
50
|
-
if (!opts || !opts.connection) {
|
|
51
|
-
throw new Error('Worker requires a connection');
|
|
52
|
-
}
|
|
53
53
|
if (typeof this.opts.maxStalledCount !== 'number' ||
|
|
54
54
|
this.opts.maxStalledCount < 0) {
|
|
55
55
|
throw new Error('maxStalledCount must be greater or equal than 0');
|
|
@@ -852,15 +852,15 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
852
852
|
reconnect && (await this.backend.reconnectBlocking());
|
|
853
853
|
}
|
|
854
854
|
async retryIfFailed(fn, opts) {
|
|
855
|
-
var _a;
|
|
855
|
+
var _a, _b;
|
|
856
856
|
let retry = 0;
|
|
857
|
-
const maxRetries = opts.maxRetries
|
|
857
|
+
const maxRetries = (_a = opts.maxRetries) !== null && _a !== void 0 ? _a : Infinity;
|
|
858
858
|
do {
|
|
859
859
|
try {
|
|
860
860
|
return await fn();
|
|
861
861
|
}
|
|
862
862
|
catch (err) {
|
|
863
|
-
(
|
|
863
|
+
(_b = opts.span) === null || _b === void 0 ? void 0 : _b.recordException(err.message);
|
|
864
864
|
if ((0, utils_1.isNotConnectionError)(err)) {
|
|
865
865
|
// Emit error when not paused or closing; optionally swallow (no throw) when opts.onlyEmitError is set.
|
|
866
866
|
if (!this.paused && !this.closing) {
|
|
@@ -874,6 +874,12 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
876
|
else {
|
|
877
|
+
if (this.closing || this.closed) {
|
|
878
|
+
if (opts.onlyEmitError) {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
throw err;
|
|
882
|
+
}
|
|
877
883
|
if (opts.delayInMs && !this.closing && !this.closed) {
|
|
878
884
|
await this.delay(opts.delayInMs, this.abortDelayController);
|
|
879
885
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -9,5 +9,6 @@ tslib_1.__exportStar(require("./utils"), exports);
|
|
|
9
9
|
// to prevent circular references
|
|
10
10
|
tslib_1.__exportStar(require("./types/processor"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./utils/create-backend"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./utils/with-backend"), exports);
|
|
12
13
|
// PostgreSQL backend (optional; requires the `pg` peer dependency at runtime).
|
|
13
14
|
tslib_1.__exportStar(require("./postgres"), exports);
|
|
@@ -10,11 +10,9 @@ const postgres_queue_backend_1 = require("./postgres-queue-backend");
|
|
|
10
10
|
* dedicated `LISTEN` client); the high-level classes depend only on
|
|
11
11
|
* `IQueueBackend` and never touch a `pg` client directly.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* only when a config/string is passed, so Redis-only users never need it
|
|
17
|
-
* installed.
|
|
13
|
+
* Accepts a connection string, pool config (optionally carrying a `schema`),
|
|
14
|
+
* or an existing `pg.Pool`. The `pg` driver is loaded lazily for config/string
|
|
15
|
+
* connections; Redis-only users do not need it installed.
|
|
18
16
|
*
|
|
19
17
|
* Inject this into the queue classes (or set it as the process-wide default via
|
|
20
18
|
* `setDefaultBackendFactory(createPostgresBackend)`) to back BullMQ with
|
|
@@ -44,7 +44,10 @@ const LISTEN_KEEPALIVE_INITIAL_DELAY_MS = 10000;
|
|
|
44
44
|
function enableSocketKeepAlive(client) {
|
|
45
45
|
var _a;
|
|
46
46
|
const stream = (_a = client.connection) === null || _a === void 0 ? void 0 : _a.stream;
|
|
47
|
-
if (!stream ||
|
|
47
|
+
if (!stream ||
|
|
48
|
+
typeof stream !== 'object' ||
|
|
49
|
+
!('setKeepAlive' in stream) ||
|
|
50
|
+
typeof stream.setKeepAlive !== 'function') {
|
|
48
51
|
return false;
|
|
49
52
|
}
|
|
50
53
|
try {
|