vona-module-a-queue 5.0.15 → 5.0.17

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.
@@ -2,4 +2,7 @@ import type * as Bull from 'bullmq';
2
2
  import type { VonaApplication } from 'vona';
3
3
  export declare function config(_app: VonaApplication): {
4
4
  worker: Bull.WorkerOptions;
5
+ queueEvents: {
6
+ waitUntilReady: number;
7
+ };
5
8
  };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BeanInfo, BeanBase, uuidv4, deepExtend, instanceDesp, beanFullNameFromOnionName, BeanSimple, BeanScopeBase, createBeanDecorator } from 'vona';
2
+ import { sleep } from '@cabloy/utils';
2
3
  import * as Bull from 'bullmq';
3
4
  import { Service, Scope } from 'vona-module-a-bean';
4
5
  import { Startup } from 'vona-module-a-startup';
@@ -200,7 +201,8 @@ let ServiceQueue = (_dec$2 = Service(), _dec2$2 = BeanInfo({
200
201
  // queueConfig.options: queue/worker/job/limiter
201
202
  const jobOptionsBase = queueConfig?.options?.job;
202
203
  // queue
203
- const queue = this._getQueue(info);
204
+ const queueQueue = this._ensureQueue(info);
205
+ const queue = queueQueue.queue;
204
206
  // job
205
207
  const jobId = info.options?.jobOptions?.jobId || uuidv4();
206
208
  const jobName = info.options?.jobName || jobId;
@@ -217,18 +219,29 @@ let ServiceQueue = (_dec$2 = Service(), _dec2$2 = BeanInfo({
217
219
  }
218
220
  // async
219
221
  return new Promise((resolve, reject) => {
220
- // callback
221
- this._queueCallbacks[jobId] = {
222
- info,
223
- callback: (err, data) => {
224
- if (err) return reject(err);
225
- resolve(data);
226
- }
227
- };
228
- // add job
229
- return queue.add(jobName, info, jobOptions);
222
+ // queue events
223
+ return this._queueEventsReady(queueQueue).then(() => {
224
+ // callback
225
+ this._queueCallbacks[jobId] = {
226
+ info,
227
+ callback: (err, data) => {
228
+ if (err) return reject(err);
229
+ resolve(data);
230
+ }
231
+ };
232
+ // add job
233
+ return queue.add(jobName, info, jobOptions);
234
+ }).catch(err => {
235
+ return reject(err);
236
+ });
230
237
  });
231
238
  }
239
+ async _queueEventsReady(queueQueue) {
240
+ if (queueQueue.queueEventsReady) return;
241
+ await queueQueue.queueEvents.waitUntilReady();
242
+ await sleep(this.scope.config.queueEvents.waitUntilReady);
243
+ queueQueue.queueEventsReady = true;
244
+ }
232
245
  _combineQueueKey(info) {
233
246
  const instanceName = instanceDesp(info.options?.instanceName);
234
247
  return `${instanceName}||${beanFullNameFromOnionName(info.queueName, 'queue')}`;
@@ -290,6 +303,9 @@ function config(_app) {
290
303
  lockDuration: 30 * 1000,
291
304
  maxStalledCount: 1000,
292
305
  stalledInterval: 10 * 1000
306
+ },
307
+ queueEvents: {
308
+ waitUntilReady: 200
293
309
  }
294
310
  };
295
311
  }
@@ -19,6 +19,7 @@ export declare class ServiceQueue extends BeanBase {
19
19
  _getQueue<DATA>(info: IQueueJobContext<DATA>): Bull.Queue<any, any, string, any, any, string>;
20
20
  _callCallback<DATA>(jobId: string | number, failedReason: string | undefined, data: DATA | undefined): void;
21
21
  _queuePush<DATA, RESULT>(info: IQueueJobContext<DATA>, isAsync: boolean): Promise<RESULT>;
22
+ _queueEventsReady(queueQueue: IQueueQueue): Promise<void>;
22
23
  _combineQueueKey<DATA>(info: IQueueJobContext<DATA>): string;
23
24
  _performTask<DATA, RESULT>(job: TypeQueueJob<DATA, RESULT>): Promise<unknown>;
24
25
  getRepeatKey(jobName: string, repeat: Bull.RepeatOptions): string;
@@ -31,6 +31,7 @@ export interface IQueueQueue {
31
31
  queue: Bull.Queue;
32
32
  queueEvents: Bull.QueueEvents;
33
33
  queueEventsOptions: Bull.QueueEventsOptions;
34
+ queueEventsReady?: boolean;
34
35
  }
35
36
  export interface IQueueQueues {
36
37
  [queueKey: string]: IQueueQueue;
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.15",
4
+ "version": "5.0.17",
5
5
  "title": "a-queue",
6
6
  "vonaModule": {
7
7
  "dependencies": {},
@@ -41,7 +41,7 @@
41
41
  "static"
42
42
  ],
43
43
  "dependencies": {
44
- "bullmq": "^5.49.1"
44
+ "bullmq": "^5.58.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "clean-package": "^2.2.0",