@midwayjs/bullmq 4.0.0-beta.8 → 4.0.0
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/framework.js +84 -14
- package/package.json +5 -5
package/dist/framework.js
CHANGED
|
@@ -216,20 +216,55 @@ let BullMQFramework = class BullMQFramework extends core_1.BaseFramework {
|
|
|
216
216
|
from: processor,
|
|
217
217
|
});
|
|
218
218
|
try {
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
219
|
+
const traceService = this.applicationContext.get(core_1.MidwayTraceService);
|
|
220
|
+
const traceMetaResolver = this.configurationOptions?.tracing
|
|
221
|
+
?.meta;
|
|
222
|
+
const traceEnabled = this.configurationOptions?.tracing?.enable !== false;
|
|
223
|
+
const traceExtractor = this.configurationOptions?.tracing
|
|
224
|
+
?.extractor;
|
|
225
|
+
const carrierDefault = job?.data?.__midwayTraceCarrier ?? {};
|
|
226
|
+
const carrier = typeof traceExtractor === 'function'
|
|
227
|
+
? traceExtractor({
|
|
228
|
+
ctx,
|
|
229
|
+
carrier: carrierDefault,
|
|
230
|
+
request: job,
|
|
231
|
+
custom: {
|
|
232
|
+
queueName,
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
: carrierDefault;
|
|
236
|
+
return await traceService.runWithEntrySpan(`bullmq ${queueName}`, {
|
|
237
|
+
enable: traceEnabled,
|
|
238
|
+
carrier: carrier ?? carrierDefault,
|
|
239
|
+
attributes: {
|
|
240
|
+
'midway.protocol': 'bullmq',
|
|
241
|
+
'midway.bullmq.queue': queueName,
|
|
242
|
+
},
|
|
243
|
+
meta: traceMetaResolver,
|
|
244
|
+
metaArgs: {
|
|
245
|
+
ctx,
|
|
246
|
+
carrier: carrier ?? carrierDefault,
|
|
247
|
+
request: job,
|
|
248
|
+
custom: {
|
|
249
|
+
queueName,
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
}, async () => {
|
|
253
|
+
ctx.logger.info(`start process job ${job.id} from ${processor.name}`);
|
|
254
|
+
const isPassed = await this.app
|
|
255
|
+
.getFramework()
|
|
256
|
+
.runGuard(ctx, processor, 'execute');
|
|
257
|
+
if (!isPassed) {
|
|
258
|
+
throw new core_1.MidwayInvokeForbiddenError('execute', processor);
|
|
259
|
+
}
|
|
260
|
+
const service = await ctx.requestContext.getAsync(processor);
|
|
261
|
+
const fn = await this.applyMiddleware(async (ctx) => {
|
|
262
|
+
return await core_1.Utils.toAsyncFunction(service.execute.bind(service))(job.data, job, token);
|
|
263
|
+
});
|
|
264
|
+
const result = await Promise.resolve(await fn(ctx));
|
|
265
|
+
ctx.logger.info(`complete process job ${job.id} from ${processor.name}`);
|
|
266
|
+
return result;
|
|
229
267
|
});
|
|
230
|
-
const result = await Promise.resolve(await fn(ctx));
|
|
231
|
-
ctx.logger.info(`complete process job ${job.id} from ${processor.name}`);
|
|
232
|
-
return result;
|
|
233
268
|
}
|
|
234
269
|
catch (err) {
|
|
235
270
|
ctx.logger.error(err);
|
|
@@ -243,7 +278,42 @@ let BullMQFramework = class BullMQFramework extends core_1.BaseFramework {
|
|
|
243
278
|
async addJobToQueue(queueName, jobData, options) {
|
|
244
279
|
const queue = this.queueMap.get(queueName);
|
|
245
280
|
if (queue) {
|
|
246
|
-
|
|
281
|
+
const traceService = this.applicationContext.get(core_1.MidwayTraceService);
|
|
282
|
+
const traceMetaResolver = this.configurationOptions?.tracing
|
|
283
|
+
?.meta;
|
|
284
|
+
const traceEnabled = this.configurationOptions?.tracing?.enable !== false;
|
|
285
|
+
const traceInjector = this.configurationOptions?.tracing
|
|
286
|
+
?.injector;
|
|
287
|
+
const payload = {
|
|
288
|
+
...(jobData ?? {}),
|
|
289
|
+
};
|
|
290
|
+
const rawCarrier = typeof traceInjector === 'function'
|
|
291
|
+
? traceInjector({
|
|
292
|
+
request: jobData,
|
|
293
|
+
custom: {
|
|
294
|
+
queueName,
|
|
295
|
+
},
|
|
296
|
+
})
|
|
297
|
+
: {};
|
|
298
|
+
const carrier = rawCarrier && typeof rawCarrier === 'object' ? rawCarrier : {};
|
|
299
|
+
payload.__midwayTraceCarrier = carrier;
|
|
300
|
+
await traceService.runWithExitSpan(`bullmq.produce ${queueName}`, {
|
|
301
|
+
enable: traceEnabled,
|
|
302
|
+
carrier,
|
|
303
|
+
attributes: {
|
|
304
|
+
'midway.protocol': 'bullmq',
|
|
305
|
+
'midway.bullmq.queue': queueName,
|
|
306
|
+
},
|
|
307
|
+
meta: traceMetaResolver,
|
|
308
|
+
metaArgs: {
|
|
309
|
+
carrier,
|
|
310
|
+
request: jobData,
|
|
311
|
+
custom: {
|
|
312
|
+
queueName,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
}, async () => undefined);
|
|
316
|
+
return await queue.addJobToQueue(payload, options);
|
|
247
317
|
}
|
|
248
318
|
}
|
|
249
319
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/bullmq",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "midway component for BullMQ",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/core": "^4.0.0
|
|
28
|
-
"@midwayjs/mock": "^4.0.0
|
|
27
|
+
"@midwayjs/core": "^4.0.0",
|
|
28
|
+
"@midwayjs/mock": "^4.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"bullmq": "5.
|
|
31
|
+
"bullmq": "5.71.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=20"
|
|
35
35
|
},
|
|
36
36
|
"repository": "https://github.com/midwayjs/midway.git",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "014f32c23ebc1d5ac21777c76be2fd373ce992d8"
|
|
38
38
|
}
|