vona-module-a-queue 5.0.33 → 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/index.js CHANGED
@@ -1,14 +1,13 @@
1
1
  import { BeanInfo, BeanBase, uuidv4, deepExtend, instanceDesp, beanFullNameFromOnionName, BeanSimple, BeanScopeBase, createBeanDecorator } from 'vona';
2
+ import { __decorate } from 'tslib';
3
+ import { catchError } from '@cabloy/utils';
2
4
  import * as Bull from 'bullmq';
3
5
  import { Service, Scope } from 'vona-module-a-bean';
4
6
  import { getRedisClientKeyPrefix } from 'vona-module-a-redis';
5
7
  import { Startup } from 'vona-module-a-startup';
6
8
  import { Hmr } from 'vona-module-a-hmr';
7
9
 
8
- var _dec$3, _dec2$3, _class$3;
9
- let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
10
- module: "a-queue"
11
- }), _dec$3(_class$3 = _dec2$3(_class$3 = class ServiceQueue extends BeanBase {
10
+ let ServiceQueue = class ServiceQueue extends BeanBase {
12
11
  constructor(...args) {
13
12
  super(...args);
14
13
  this._workers = {};
@@ -19,7 +18,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
19
18
  if (!info.options?.dbInfo) throw new Error('should specify the options.dbInfo');
20
19
  this._queuePush(info, false);
21
20
  }
22
-
23
21
  // { locale, instanceName, module, queueName,queueNameSub,data }
24
22
  pushAsync(info) {
25
23
  if (!info.options?.dbInfo) throw new Error('should specify the options.dbInfo');
@@ -67,12 +65,10 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
67
65
  const workerOptions = queueConfig?.options?.worker;
68
66
  const redlockOptions = queueConfig?.options?.redlock;
69
67
  const _lockTTL = redlockOptions?.lockTTL ?? this.$scope.redlock.config.lockTTL;
70
-
71
68
  // redlock
72
69
  if (!queueConfig?.concurrency) {
73
70
  _worker.redlock = this.$scope.redlock.service.redlock.create(redlockOptions);
74
71
  }
75
-
76
72
  // create work
77
73
  const connectionWorker = app.bean.redis.get('queue');
78
74
  const _workerOptions = Object.assign({}, this.scope.config.worker, workerOptions, {
@@ -83,14 +79,14 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
83
79
  _worker.worker = new Bull.Worker(queueKey, async job => {
84
80
  // concurrency
85
81
  if (queueConfig?.concurrency) {
86
- return await this._performTask(job);
82
+ return await this._performTaskWrapper(job);
87
83
  }
88
84
  // redlock
89
85
  const info = job.data;
90
86
  const queueNameSub = info.options?.queueNameSub;
91
87
  const _lockResource = `queue:${queueKey}${queueNameSub ? `#${queueNameSub}` : ''}`;
92
88
  return await this.$scope.redlock.service.redlock.lock(_lockResource, async () => {
93
- return await this._performTask(job);
89
+ return await this._performTaskWrapper(job);
94
90
  }, {
95
91
  // instanceName: job.data.instanceName, // need not
96
92
  redlock: _worker.redlock,
@@ -110,7 +106,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
110
106
  }
111
107
  }
112
108
  });
113
-
114
109
  // ok
115
110
  return _worker;
116
111
  }
@@ -124,7 +119,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
124
119
  const queueConfig = app.bean.onion.queue.getOnionOptions(info.queueName);
125
120
  // queueConfig.options: queue/worker/job/limiter
126
121
  const queueOptions = queueConfig?.options?.queue;
127
-
128
122
  // create queue
129
123
  const connectionQueue = app.bean.redis.get('queue');
130
124
  const _queueOptions = Object.assign({}, queueOptions, {
@@ -134,7 +128,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
134
128
  _queue.config = queueConfig;
135
129
  _queue.options = _queueOptions;
136
130
  _queue.queue = new Bull.Queue(queueKey, _queueOptions);
137
-
138
131
  // create events
139
132
  const connectionEvents = app.bean.redis.get('queue');
140
133
  const _queueEventsOptions = {
@@ -155,7 +148,6 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
155
148
  }) => {
156
149
  this._callCallback(jobId, failedReason, undefined);
157
150
  });
158
-
159
151
  // ok
160
152
  return _queue;
161
153
  }
@@ -248,6 +240,17 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
248
240
  const instanceName = instanceDesp(info.options?.instanceName);
249
241
  return `${instanceName}||${beanFullNameFromOnionName(info.queueName, 'queue')}`;
250
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
+ }
251
254
  async _performTask(job) {
252
255
  const info = job.data;
253
256
  // queue config
@@ -283,31 +286,34 @@ let ServiceQueue = (_dec$3 = Service(), _dec2$3 = BeanInfo({
283
286
  options
284
287
  };
285
288
  }
286
- }) || _class$3) || _class$3);
287
-
288
- var _dec$2, _dec2$2, _class$2;
289
- let StartupLoadQueueWorkers = (_dec$2 = Startup({
290
- instance: true,
291
- after: true
292
- }), _dec2$2 = BeanInfo({
289
+ };
290
+ ServiceQueue = __decorate([Service(), BeanInfo({
293
291
  module: "a-queue"
294
- }), _dec$2(_class$2 = _dec2$2(_class$2 = class StartupLoadQueueWorkers extends BeanBase {
292
+ })], ServiceQueue);
293
+
294
+ let StartupLoadQueueWorkers = class StartupLoadQueueWorkers extends BeanBase {
295
295
  async execute() {
296
296
  // load queue workers
297
297
  if (!this.app.meta.isTest) {
298
298
  this.scope.service.queue.loadQueueWorkers(this.ctx.instanceName);
299
299
  }
300
300
  }
301
- }) || _class$2) || _class$2);
302
-
303
- var _dec$1, _dec2$1, _class$1;
304
- let HmrQueue = (_dec$1 = Hmr(), _dec2$1 = BeanInfo({
301
+ };
302
+ StartupLoadQueueWorkers = __decorate([Startup({
303
+ instance: true,
304
+ after: true
305
+ }), BeanInfo({
305
306
  module: "a-queue"
306
- }), _dec$1(_class$1 = _dec2$1(_class$1 = class HmrQueue extends BeanBase {
307
+ })], StartupLoadQueueWorkers);
308
+
309
+ let HmrQueue = class HmrQueue extends BeanBase {
307
310
  async reload(_beanOptions) {
308
311
  this.app.bean.worker.reload();
309
312
  }
310
- }) || _class$1) || _class$1);
313
+ };
314
+ HmrQueue = __decorate([Hmr(), BeanInfo({
315
+ module: "a-queue"
316
+ })], HmrQueue);
311
317
 
312
318
  function config(_app) {
313
319
  return {
@@ -332,11 +338,10 @@ class Monkey extends BeanSimple {
332
338
  }
333
339
  }
334
340
 
335
- var _dec, _dec2, _class;
336
- let ScopeModuleAQueue = (_dec = Scope(), _dec2 = BeanInfo({
341
+ let ScopeModuleAQueue = class ScopeModuleAQueue extends BeanScopeBase {};
342
+ ScopeModuleAQueue = __decorate([Scope(), BeanInfo({
337
343
  module: "a-queue"
338
- }), _dec(_class = _dec2(_class = class ScopeModuleAQueue extends BeanScopeBase {}) || _class) || _class);
339
-
344
+ })], ScopeModuleAQueue);
340
345
  /** scope: end */
341
346
 
342
347
  class BeanQueueBase extends BeanBase {
@@ -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.33",
4
+ "version": "5.0.34",
5
5
  "title": "a-queue",
6
6
  "vonaModule": {
7
7
  "dependencies": {},