vona-module-a-queue 5.0.32 → 5.0.34
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/config/config.d.ts +0 -3
- package/dist/index.js +36 -39
- package/dist/service/queue.d.ts +1 -0
- package/package.json +2 -2
package/dist/config/config.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { BeanInfo, BeanBase, uuidv4, deepExtend, instanceDesp, beanFullNameFromOnionName, BeanSimple, BeanScopeBase, createBeanDecorator } from 'vona';
|
|
2
|
-
import {
|
|
2
|
+
import { __decorate } from 'tslib';
|
|
3
|
+
import { catchError } from '@cabloy/utils';
|
|
3
4
|
import * as Bull from 'bullmq';
|
|
4
5
|
import { Service, Scope } from 'vona-module-a-bean';
|
|
5
6
|
import { getRedisClientKeyPrefix } from 'vona-module-a-redis';
|
|
6
7
|
import { Startup } from 'vona-module-a-startup';
|
|
7
8
|
import { Hmr } from 'vona-module-a-hmr';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
11
|
-
module: "a-queue"
|
|
12
|
-
}), _dec$3(_class$3 = _dec2$3(_class$3 = class ServiceQueue extends BeanBase {
|
|
10
|
+
let ServiceQueue = class ServiceQueue extends BeanBase {
|
|
13
11
|
constructor(...args) {
|
|
14
12
|
super(...args);
|
|
15
13
|
this._workers = {};
|
|
@@ -20,7 +18,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
20
18
|
if (!info.options?.dbInfo) throw new Error('should specify the options.dbInfo');
|
|
21
19
|
this._queuePush(info, false);
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
// { locale, instanceName, module, queueName,queueNameSub,data }
|
|
25
22
|
pushAsync(info) {
|
|
26
23
|
if (!info.options?.dbInfo) throw new Error('should specify the options.dbInfo');
|
|
@@ -68,12 +65,10 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
68
65
|
const workerOptions = queueConfig?.options?.worker;
|
|
69
66
|
const redlockOptions = queueConfig?.options?.redlock;
|
|
70
67
|
const _lockTTL = redlockOptions?.lockTTL ?? this.$scope.redlock.config.lockTTL;
|
|
71
|
-
|
|
72
68
|
// redlock
|
|
73
69
|
if (!queueConfig?.concurrency) {
|
|
74
70
|
_worker.redlock = this.$scope.redlock.service.redlock.create(redlockOptions);
|
|
75
71
|
}
|
|
76
|
-
|
|
77
72
|
// create work
|
|
78
73
|
const connectionWorker = app.bean.redis.get('queue');
|
|
79
74
|
const _workerOptions = Object.assign({}, this.scope.config.worker, workerOptions, {
|
|
@@ -84,14 +79,14 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
84
79
|
_worker.worker = new Bull.Worker(queueKey, async job => {
|
|
85
80
|
// concurrency
|
|
86
81
|
if (queueConfig?.concurrency) {
|
|
87
|
-
return await this.
|
|
82
|
+
return await this._performTaskWrapper(job);
|
|
88
83
|
}
|
|
89
84
|
// redlock
|
|
90
85
|
const info = job.data;
|
|
91
86
|
const queueNameSub = info.options?.queueNameSub;
|
|
92
87
|
const _lockResource = `queue:${queueKey}${queueNameSub ? `#${queueNameSub}` : ''}`;
|
|
93
88
|
return await this.$scope.redlock.service.redlock.lock(_lockResource, async () => {
|
|
94
|
-
return await this.
|
|
89
|
+
return await this._performTaskWrapper(job);
|
|
95
90
|
}, {
|
|
96
91
|
// instanceName: job.data.instanceName, // need not
|
|
97
92
|
redlock: _worker.redlock,
|
|
@@ -111,7 +106,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
111
106
|
}
|
|
112
107
|
}
|
|
113
108
|
});
|
|
114
|
-
|
|
115
109
|
// ok
|
|
116
110
|
return _worker;
|
|
117
111
|
}
|
|
@@ -125,7 +119,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
125
119
|
const queueConfig = app.bean.onion.queue.getOnionOptions(info.queueName);
|
|
126
120
|
// queueConfig.options: queue/worker/job/limiter
|
|
127
121
|
const queueOptions = queueConfig?.options?.queue;
|
|
128
|
-
|
|
129
122
|
// create queue
|
|
130
123
|
const connectionQueue = app.bean.redis.get('queue');
|
|
131
124
|
const _queueOptions = Object.assign({}, queueOptions, {
|
|
@@ -135,7 +128,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
135
128
|
_queue.config = queueConfig;
|
|
136
129
|
_queue.options = _queueOptions;
|
|
137
130
|
_queue.queue = new Bull.Queue(queueKey, _queueOptions);
|
|
138
|
-
|
|
139
131
|
// create events
|
|
140
132
|
const connectionEvents = app.bean.redis.get('queue');
|
|
141
133
|
const _queueEventsOptions = {
|
|
@@ -156,7 +148,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
156
148
|
}) => {
|
|
157
149
|
this._callCallback(jobId, failedReason, undefined);
|
|
158
150
|
});
|
|
159
|
-
|
|
160
151
|
// ok
|
|
161
152
|
return _queue;
|
|
162
153
|
}
|
|
@@ -243,16 +234,23 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
243
234
|
async _queueEventsReady(queueQueue) {
|
|
244
235
|
if (queueQueue.queueEventsReady) return;
|
|
245
236
|
await queueQueue.queueEvents.waitUntilReady();
|
|
246
|
-
const waitUntilReady = this.scope.config.queueEvents.waitUntilReady;
|
|
247
|
-
if (waitUntilReady) {
|
|
248
|
-
await sleep(waitUntilReady);
|
|
249
|
-
}
|
|
250
237
|
queueQueue.queueEventsReady = true;
|
|
251
238
|
}
|
|
252
239
|
_combineQueueKey(info) {
|
|
253
240
|
const instanceName = instanceDesp(info.options?.instanceName);
|
|
254
241
|
return `${instanceName}||${beanFullNameFromOnionName(info.queueName, 'queue')}`;
|
|
255
242
|
}
|
|
243
|
+
async _performTaskWrapper(job) {
|
|
244
|
+
const [res, err] = await catchError(() => {
|
|
245
|
+
return this._performTask(job);
|
|
246
|
+
});
|
|
247
|
+
if (err) {
|
|
248
|
+
await this.app.handleError(err);
|
|
249
|
+
throw err;
|
|
250
|
+
} else {
|
|
251
|
+
return res;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
256
254
|
async _performTask(job) {
|
|
257
255
|
const info = job.data;
|
|
258
256
|
// queue config
|
|
@@ -288,31 +286,34 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
|
|
|
288
286
|
options
|
|
289
287
|
};
|
|
290
288
|
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
var _dec$2, _dec2$2, _class$2;
|
|
294
|
-
let StartupLoadQueueWorkers = (_dec$2 = Startup({
|
|
295
|
-
instance: true,
|
|
296
|
-
after: true
|
|
297
|
-
}), _dec2$2 = BeanInfo({
|
|
289
|
+
};
|
|
290
|
+
ServiceQueue = __decorate([Service(), BeanInfo({
|
|
298
291
|
module: "a-queue"
|
|
299
|
-
}),
|
|
292
|
+
})], ServiceQueue);
|
|
293
|
+
|
|
294
|
+
let StartupLoadQueueWorkers = class StartupLoadQueueWorkers extends BeanBase {
|
|
300
295
|
async execute() {
|
|
301
296
|
// load queue workers
|
|
302
297
|
if (!this.app.meta.isTest) {
|
|
303
298
|
this.scope.service.queue.loadQueueWorkers(this.ctx.instanceName);
|
|
304
299
|
}
|
|
305
300
|
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
301
|
+
};
|
|
302
|
+
StartupLoadQueueWorkers = __decorate([Startup({
|
|
303
|
+
instance: true,
|
|
304
|
+
after: true
|
|
305
|
+
}), BeanInfo({
|
|
310
306
|
module: "a-queue"
|
|
311
|
-
}),
|
|
307
|
+
})], StartupLoadQueueWorkers);
|
|
308
|
+
|
|
309
|
+
let HmrQueue = class HmrQueue extends BeanBase {
|
|
312
310
|
async reload(_beanOptions) {
|
|
313
311
|
this.app.bean.worker.reload();
|
|
314
312
|
}
|
|
315
|
-
}
|
|
313
|
+
};
|
|
314
|
+
HmrQueue = __decorate([Hmr(), BeanInfo({
|
|
315
|
+
module: "a-queue"
|
|
316
|
+
})], HmrQueue);
|
|
316
317
|
|
|
317
318
|
function config(_app) {
|
|
318
319
|
return {
|
|
@@ -320,9 +321,6 @@ function config(_app) {
|
|
|
320
321
|
lockDuration: 30 * 1000,
|
|
321
322
|
maxStalledCount: 1000,
|
|
322
323
|
stalledInterval: 10 * 1000
|
|
323
|
-
},
|
|
324
|
-
queueEvents: {
|
|
325
|
-
waitUntilReady: 200
|
|
326
324
|
}
|
|
327
325
|
};
|
|
328
326
|
}
|
|
@@ -340,11 +338,10 @@ class Monkey extends BeanSimple {
|
|
|
340
338
|
}
|
|
341
339
|
}
|
|
342
340
|
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
let ScopeModuleAQueue = class ScopeModuleAQueue extends BeanScopeBase {};
|
|
342
|
+
ScopeModuleAQueue = __decorate([Scope(), BeanInfo({
|
|
345
343
|
module: "a-queue"
|
|
346
|
-
}),
|
|
347
|
-
|
|
344
|
+
})], ScopeModuleAQueue);
|
|
348
345
|
/** scope: end */
|
|
349
346
|
|
|
350
347
|
class BeanQueueBase extends BeanBase {
|
package/dist/service/queue.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class ServiceQueue extends BeanBase {
|
|
|
22
22
|
_queuePush<DATA, RESULT>(info: IQueueJobContext<DATA>, isAsync: boolean): Promise<RESULT>;
|
|
23
23
|
_queueEventsReady(queueQueue: IQueueQueue): Promise<void>;
|
|
24
24
|
_combineQueueKey<DATA>(info: IQueueJobContext<DATA>): string;
|
|
25
|
+
_performTaskWrapper<DATA, RESULT>(job: TypeQueueJob<DATA, RESULT>): Promise<unknown>;
|
|
25
26
|
_performTask<DATA, RESULT>(job: TypeQueueJob<DATA, RESULT>): Promise<unknown>;
|
|
26
27
|
getRepeatKey(jobName: string, repeat: Bull.RepeatOptions): string;
|
|
27
28
|
prepareJobInfo<DATA>(queueName: keyof IQueueRecord, data: DATA, options?: IQueuePushOptions): IQueueJobContext<DATA>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-module-a-queue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.34",
|
|
5
5
|
"title": "a-queue",
|
|
6
6
|
"vonaModule": {
|
|
7
7
|
"dependencies": {},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"bullmq": "^5.
|
|
44
|
+
"bullmq": "^5.66.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"clean-package": "^2.2.0",
|