@midwayjs/piscina 4.0.0-beta.11 → 4.0.0-beta.13

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 CHANGED
@@ -44,11 +44,43 @@ let PiscinaWorkerFramework = class PiscinaWorkerFramework extends core_1.BaseFra
44
44
  throw new core_1.MidwayCommonError(`Task handler "${handler}" not found. Did you forget to use @PiscinaTask('${handler}') decorator?`);
45
45
  }
46
46
  const ctx = this.app.createAnonymousContext();
47
- const taskInstance = await ctx.requestContext.getAsync(TaskClass);
48
- if (!taskInstance || typeof taskInstance.execute !== 'function') {
49
- throw new core_1.MidwayCommonError(`Task "${handler}" must implement execute method`);
50
- }
51
- return await taskInstance.execute(payload);
47
+ const traceService = this.applicationContext.get(core_1.MidwayTraceService);
48
+ const traceMetaResolver = this.configurationOptions?.tracing?.meta;
49
+ const traceEnabled = this.configurationOptions?.tracing?.enable !== false;
50
+ const traceExtractor = this.configurationOptions?.tracing
51
+ ?.extractor;
52
+ const entryCarrier = typeof traceExtractor === 'function'
53
+ ? traceExtractor({
54
+ ctx,
55
+ request: payload,
56
+ custom: {
57
+ handler,
58
+ },
59
+ })
60
+ : {};
61
+ return await traceService.runWithEntrySpan(`piscina ${handler}`, {
62
+ enable: traceEnabled,
63
+ carrier: entryCarrier,
64
+ attributes: {
65
+ 'midway.protocol': 'piscina',
66
+ 'midway.piscina.handler': handler,
67
+ },
68
+ meta: traceMetaResolver,
69
+ metaArgs: {
70
+ ctx,
71
+ carrier: entryCarrier,
72
+ request: payload,
73
+ custom: {
74
+ handler,
75
+ },
76
+ },
77
+ }, async () => {
78
+ const taskInstance = await ctx.requestContext.getAsync(TaskClass);
79
+ if (!taskInstance || typeof taskInstance.execute !== 'function') {
80
+ throw new core_1.MidwayCommonError(`Task "${handler}" must implement execute method`);
81
+ }
82
+ return await taskInstance.execute(payload);
83
+ });
52
84
  }
53
85
  /**
54
86
  * 获取所有已注册的 handler
@@ -45,7 +45,6 @@ if (fullpath) {
45
45
  // 查找 worker 目录中的 tsconfig.json
46
46
  const workerTsConfig = path.join(baseDir, 'tsconfig.json');
47
47
  const hasWorkerTsConfig = fs.existsSync(workerTsConfig);
48
- /* eslint-disable-next-line node/no-extraneous-require */
49
48
  require('ts-node').register(hasWorkerTsConfig
50
49
  ? { project: workerTsConfig }
51
50
  : {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/piscina",
3
- "version": "4.0.0-beta.11",
3
+ "version": "4.0.0-beta.13",
4
4
  "description": "Midway Component for Piscina worker thread pool",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -28,12 +28,12 @@
28
28
  },
29
29
  "license": "MIT",
30
30
  "devDependencies": {
31
- "@midwayjs/core": "^4.0.0-beta.11",
31
+ "@midwayjs/core": "^4.0.0-beta.13",
32
32
  "@midwayjs/logger": "^4.0.0",
33
- "@midwayjs/mock": "^4.0.0-beta.11"
33
+ "@midwayjs/mock": "^4.0.0-beta.13"
34
34
  },
35
35
  "dependencies": {
36
36
  "piscina": "5.1.4"
37
37
  },
38
- "gitHead": "6ef05719ca6e900f1ec34aff7a5c5a9614358c50"
38
+ "gitHead": "9a38b66a84a6880370cac90d737f94f9c5f2f256"
39
39
  }