@midwayjs/cron 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 +50 -19
- package/package.json +4 -4
package/dist/framework.js
CHANGED
|
@@ -55,26 +55,57 @@ let CronFramework = class CronFramework extends core_1.BaseFramework {
|
|
|
55
55
|
job: this,
|
|
56
56
|
from: name,
|
|
57
57
|
});
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
const traceService = self.applicationContext.get(core_1.MidwayTraceService);
|
|
59
|
+
const traceMetaResolver = self.configurationOptions?.tracing
|
|
60
|
+
?.meta;
|
|
61
|
+
const traceEnabled = self.configurationOptions?.tracing?.enable !== false;
|
|
62
|
+
const traceExtractor = self.configurationOptions?.tracing
|
|
63
|
+
?.extractor;
|
|
64
|
+
const entryCarrier = typeof traceExtractor === 'function'
|
|
65
|
+
? traceExtractor({
|
|
66
|
+
ctx,
|
|
67
|
+
request: this,
|
|
68
|
+
custom: { jobName: name.name },
|
|
69
|
+
})
|
|
70
|
+
: {};
|
|
71
|
+
await traceService.runWithEntrySpan(`cron ${name.name}`, {
|
|
72
|
+
enable: traceEnabled,
|
|
73
|
+
carrier: entryCarrier,
|
|
74
|
+
attributes: {
|
|
75
|
+
'midway.protocol': 'cron',
|
|
76
|
+
'midway.cron.job': name.name,
|
|
77
|
+
},
|
|
78
|
+
meta: traceMetaResolver,
|
|
79
|
+
metaArgs: {
|
|
80
|
+
ctx,
|
|
81
|
+
carrier: entryCarrier,
|
|
82
|
+
request: this,
|
|
83
|
+
custom: {
|
|
84
|
+
jobName: name.name,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
}, async () => {
|
|
88
|
+
ctx.logger.info(`start job ${name.name}`);
|
|
89
|
+
const isPassed = await self.app
|
|
90
|
+
.getFramework()
|
|
91
|
+
.runGuard(ctx, name, 'onTick');
|
|
92
|
+
if (!isPassed) {
|
|
93
|
+
throw new core_1.MidwayInvokeForbiddenError('onTick', name);
|
|
94
|
+
}
|
|
95
|
+
const service = await ctx.requestContext.getAsync(name);
|
|
96
|
+
const fn = await self.applyMiddleware(async (ctx) => {
|
|
97
|
+
return await core_1.Utils.toAsyncFunction(service.onTick.bind(service))();
|
|
98
|
+
});
|
|
99
|
+
try {
|
|
100
|
+
const result = await Promise.resolve(await fn(ctx));
|
|
101
|
+
ctx.logger.info(`complete job ${name.name}`);
|
|
102
|
+
await service.onComplete?.(result);
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
ctx.logger.error(err);
|
|
107
|
+
}
|
|
68
108
|
});
|
|
69
|
-
try {
|
|
70
|
-
const result = await Promise.resolve(await fn(ctx));
|
|
71
|
-
ctx.logger.info(`complete job ${name.name}`);
|
|
72
|
-
await service.onComplete?.(result);
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
ctx.logger.error(err);
|
|
77
|
-
}
|
|
78
109
|
})().catch(err => {
|
|
79
110
|
self.logger.error(`error in job from ${name.name}: ${err.stack}`);
|
|
80
111
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/cron",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.13",
|
|
4
4
|
"description": "Midway Component for Cron",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"cron": "3.5.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@midwayjs/core": "^4.0.0-beta.
|
|
33
|
-
"@midwayjs/mock": "^4.0.0-beta.
|
|
32
|
+
"@midwayjs/core": "^4.0.0-beta.13",
|
|
33
|
+
"@midwayjs/mock": "^4.0.0-beta.13"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "9a38b66a84a6880370cac90d737f94f9c5f2f256"
|
|
36
36
|
}
|