@midwayjs/bull 4.0.0-beta.9 → 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/index.d.ts +0 -1
- package/package.json +4 -4
package/dist/framework.js
CHANGED
|
@@ -106,20 +106,55 @@ let BullFramework = class BullFramework extends core_1.BaseFramework {
|
|
|
106
106
|
from: processor,
|
|
107
107
|
});
|
|
108
108
|
try {
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
const traceService = this.applicationContext.get(core_1.MidwayTraceService);
|
|
110
|
+
const traceMetaResolver = this.configurationOptions?.tracing
|
|
111
|
+
?.meta;
|
|
112
|
+
const traceEnabled = this.configurationOptions?.tracing?.enable !== false;
|
|
113
|
+
const traceExtractor = this.configurationOptions?.tracing
|
|
114
|
+
?.extractor;
|
|
115
|
+
const carrierDefault = job?.data?.__midwayTraceCarrier ?? {};
|
|
116
|
+
const carrier = typeof traceExtractor === 'function'
|
|
117
|
+
? traceExtractor({
|
|
118
|
+
ctx,
|
|
119
|
+
carrier: carrierDefault,
|
|
120
|
+
request: job,
|
|
121
|
+
custom: {
|
|
122
|
+
queueName: queue.getQueueName(),
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
: carrierDefault;
|
|
126
|
+
return await traceService.runWithEntrySpan(`bull ${queue.getQueueName()}`, {
|
|
127
|
+
enable: traceEnabled,
|
|
128
|
+
carrier: carrier ?? carrierDefault,
|
|
129
|
+
attributes: {
|
|
130
|
+
'midway.protocol': 'bull',
|
|
131
|
+
'midway.bull.queue': queue.getQueueName(),
|
|
132
|
+
},
|
|
133
|
+
meta: traceMetaResolver,
|
|
134
|
+
metaArgs: {
|
|
135
|
+
ctx,
|
|
136
|
+
carrier: carrier ?? carrierDefault,
|
|
137
|
+
request: job,
|
|
138
|
+
custom: {
|
|
139
|
+
queueName: queue.getQueueName(),
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
}, async () => {
|
|
143
|
+
ctx.logger.info(`start process job ${job.id} from ${processor.name}`);
|
|
144
|
+
const isPassed = await this.app
|
|
145
|
+
.getFramework()
|
|
146
|
+
.runGuard(ctx, processor, 'execute');
|
|
147
|
+
if (!isPassed) {
|
|
148
|
+
throw new core_1.MidwayInvokeForbiddenError('execute', processor);
|
|
149
|
+
}
|
|
150
|
+
const service = await ctx.requestContext.getAsync(processor);
|
|
151
|
+
const fn = await this.applyMiddleware(async (ctx) => {
|
|
152
|
+
return await core_1.Utils.toAsyncFunction(service.execute.bind(service))(job.data, job);
|
|
153
|
+
});
|
|
154
|
+
const result = await Promise.resolve(await fn(ctx));
|
|
155
|
+
ctx.logger.info(`complete process job ${job.id} from ${processor.name}`);
|
|
156
|
+
return result;
|
|
119
157
|
});
|
|
120
|
-
const result = await Promise.resolve(await fn(ctx));
|
|
121
|
-
ctx.logger.info(`complete process job ${job.id} from ${processor.name}`);
|
|
122
|
-
return result;
|
|
123
158
|
}
|
|
124
159
|
catch (err) {
|
|
125
160
|
ctx.logger.error(err);
|
|
@@ -130,7 +165,42 @@ let BullFramework = class BullFramework extends core_1.BaseFramework {
|
|
|
130
165
|
async addJobToQueue(queueName, jobData, options) {
|
|
131
166
|
const queue = this.queueMap.get(queueName);
|
|
132
167
|
if (queue) {
|
|
133
|
-
|
|
168
|
+
const traceService = this.applicationContext.get(core_1.MidwayTraceService);
|
|
169
|
+
const traceMetaResolver = this.configurationOptions?.tracing
|
|
170
|
+
?.meta;
|
|
171
|
+
const traceEnabled = this.configurationOptions?.tracing?.enable !== false;
|
|
172
|
+
const traceInjector = this.configurationOptions?.tracing
|
|
173
|
+
?.injector;
|
|
174
|
+
const payload = {
|
|
175
|
+
...(jobData ?? {}),
|
|
176
|
+
};
|
|
177
|
+
const rawCarrier = typeof traceInjector === 'function'
|
|
178
|
+
? traceInjector({
|
|
179
|
+
request: jobData,
|
|
180
|
+
custom: {
|
|
181
|
+
queueName,
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
: {};
|
|
185
|
+
const exitCarrier = rawCarrier && typeof rawCarrier === 'object' ? rawCarrier : {};
|
|
186
|
+
payload.__midwayTraceCarrier = exitCarrier;
|
|
187
|
+
await traceService.runWithExitSpan(`bull.produce ${queueName}`, {
|
|
188
|
+
enable: traceEnabled,
|
|
189
|
+
carrier: exitCarrier,
|
|
190
|
+
attributes: {
|
|
191
|
+
'midway.protocol': 'bull',
|
|
192
|
+
'midway.bull.queue': queueName,
|
|
193
|
+
},
|
|
194
|
+
meta: traceMetaResolver,
|
|
195
|
+
metaArgs: {
|
|
196
|
+
carrier: exitCarrier,
|
|
197
|
+
request: jobData,
|
|
198
|
+
custom: {
|
|
199
|
+
queueName,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
}, async () => undefined);
|
|
203
|
+
return await queue.addJobToQueue(payload, options);
|
|
134
204
|
}
|
|
135
205
|
}
|
|
136
206
|
/**
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/bull",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "midway component for bull",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
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
31
|
"bull": "4.16.5"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=20"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "014f32c23ebc1d5ac21777c76be2fd373ce992d8"
|
|
37
37
|
}
|