@midwayjs/bull 3.0.0 → 3.0.1

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.
@@ -5,6 +5,7 @@ export declare const bull: {
5
5
  contextLoggerApplyLogger: string;
6
6
  contextLoggerFormat: (info: any) => string;
7
7
  defaultConcurrency: number;
8
+ clearJobWhenStart: boolean;
8
9
  };
9
10
  export declare const midwayLogger: {
10
11
  clients: {
@@ -11,6 +11,7 @@ exports.bull = {
11
11
  return `${info.timestamp} ${info.LEVEL} ${info.pid} [${jobId} ${triggerName}] ${info.message}`;
12
12
  },
13
13
  defaultConcurrency: 1,
14
+ clearJobWhenStart: true,
14
15
  };
15
16
  exports.midwayLogger = {
16
17
  clients: {
package/dist/constants.js CHANGED
@@ -4,5 +4,4 @@ exports.BULL_PROCESSOR_KEY = exports.BULL_QUEUE_KEY = void 0;
4
4
  // task
5
5
  exports.BULL_QUEUE_KEY = 'bull:queue';
6
6
  exports.BULL_PROCESSOR_KEY = 'bull:processor';
7
- // export const BULL_REPEATABLE_PROCESSOR_KEY = 'bull:repeatableProcessor';
8
7
  //# sourceMappingURL=constants.js.map
@@ -10,6 +10,7 @@ export declare class BullQueue extends Bull implements IQueue<Job> {
10
10
  export declare class BullFramework extends BaseFramework<Application, Context, any> implements IQueueManager<BullQueue, Job> {
11
11
  private bullDefaultQueueConfig;
12
12
  private bullDefaultConcurrency;
13
+ private bullClearJobWhenStart;
13
14
  private queueMap;
14
15
  applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
15
16
  configure(): any;
package/dist/framework.js CHANGED
@@ -32,6 +32,7 @@ let BullFramework = class BullFramework extends core_1.BaseFramework {
32
32
  this.app = {};
33
33
  this.bullDefaultQueueConfig = this.configService.getConfiguration('bull.defaultQueueOptions');
34
34
  this.bullDefaultConcurrency = this.configService.getConfiguration('bull.defaultConcurrency');
35
+ this.bullClearJobWhenStart = this.configService.getConfiguration('bull.bullClearJobWhenStart');
35
36
  }
36
37
  configure() {
37
38
  return this.configService.getConfiguration('bull');
@@ -45,6 +46,10 @@ let BullFramework = class BullFramework extends core_1.BaseFramework {
45
46
  for (const mod of processorModules) {
46
47
  const options = (0, decorator_1.getClassMetadata)(constants_1.BULL_PROCESSOR_KEY, mod);
47
48
  this.ensureQueue(options.queueName);
49
+ // clear old job when start
50
+ if (this.bullClearJobWhenStart) {
51
+ await this.queueMap.get(options.queueName).obliterate({ force: true });
52
+ }
48
53
  await this.addProcessor(mod, options.queueName, options.concurrency);
49
54
  if ((_a = options.jobOptions) === null || _a === void 0 ? void 0 : _a.repeat) {
50
55
  await this.runJob(options.queueName, {}, options.jobOptions);
@@ -77,15 +82,17 @@ let BullFramework = class BullFramework extends core_1.BaseFramework {
77
82
  const ctx = this.app.createAnonymousContext({
78
83
  jobId: job.id,
79
84
  job,
80
- triggerName: (0, decorator_1.getProviderName)(processor),
81
- triggerUUID: (0, decorator_1.getProviderUUId)(processor),
85
+ from: processor,
82
86
  });
87
+ ctx.logger.info(`[@midwayjs/bull] start process job ${job.id} from ${processor.name}`);
83
88
  const service = await ctx.requestContext.getAsync(processor);
84
89
  const fn = await this.applyMiddleware(async (ctx) => {
85
90
  return await decorator_1.Utils.toAsyncFunction(service.execute.bind(service))(job.data, job);
86
91
  });
87
92
  try {
88
- return Promise.resolve(await fn(ctx));
93
+ const result = await Promise.resolve(await fn(ctx));
94
+ ctx.logger.info(`[@midwayjs/bull] complete process job ${job.id} from ${processor.name}`);
95
+ return result;
89
96
  }
90
97
  catch (err) {
91
98
  ctx.logger.error(err);
@@ -20,7 +20,6 @@ export declare type NextFunction = BaseNextFunction;
20
20
  export interface Context extends IMidwayContext {
21
21
  jobId: JobId;
22
22
  job: Job;
23
- triggerName: string;
24
- triggerUUID: string;
23
+ from: new (...args: any[]) => IProcessor;
25
24
  }
26
25
  //# sourceMappingURL=interface.d.ts.map
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ declare module '@midwayjs/core/dist/interface' {
8
8
  defaultQueueOptions?: bull.QueueOptions;
9
9
  defaultJobOptions?: bull.JobOptions;
10
10
  defaultConcurrency?: number;
11
+ clearJobWhenStart?: boolean;
11
12
  };
12
13
  }
13
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/bull",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "midway component for bull",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",