@zenweb/schedule 3.0.1 → 3.1.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/index.js +1 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +13 -2
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ function setup(option) {
|
|
|
12
12
|
return async function schedule(setup) {
|
|
13
13
|
setup.checkCoreProperty('injector', '@zenweb/inject');
|
|
14
14
|
setup.checkCoreProperty('router', '@zenweb/router');
|
|
15
|
+
setup.checkCoreProperty('log', '@zenweb/log');
|
|
15
16
|
setup.debug('option: %o', option);
|
|
16
17
|
setup.defineCoreProperty('schedule', { value: true });
|
|
17
18
|
if (option.paths && option.paths.length) {
|
package/dist/register.d.ts
CHANGED
package/dist/register.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.registerSchedule = exports.schedule = exports.addJob = exports.getJobs = void 0;
|
|
4
4
|
require("@zenweb/inject");
|
|
5
5
|
require("@zenweb/router");
|
|
6
|
+
require("@zenweb/log");
|
|
6
7
|
const http_1 = require("http");
|
|
7
8
|
const node_schedule_1 = require("node-schedule");
|
|
8
9
|
const crypto_1 = require("crypto");
|
|
@@ -11,11 +12,21 @@ const JOBS = Symbol('Schedule#jobs');
|
|
|
11
12
|
/**
|
|
12
13
|
* 安全检查,防止外部调用
|
|
13
14
|
*/
|
|
14
|
-
function safeCheck(ctx, next) {
|
|
15
|
+
async function safeCheck(ctx, next) {
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
ctx.log.info('start');
|
|
15
18
|
if (!ctx.req.socket.remoteAddress || !ctx.req.socket.remoteAddress.endsWith(SAFE_IP)) {
|
|
16
19
|
ctx.throw(403);
|
|
17
20
|
}
|
|
18
|
-
|
|
21
|
+
try {
|
|
22
|
+
await next();
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
ctx.log.child({ err }).error('error');
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
ctx.log.info('end', Date.now() - startTime, 'ms');
|
|
29
|
+
}
|
|
19
30
|
}
|
|
20
31
|
/**
|
|
21
32
|
* 取得对象中的任务列表
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenweb/schedule",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Zenweb Schedule module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@zenweb/core": "^2.4.1",
|
|
37
37
|
"@zenweb/inject": "^3.5.0",
|
|
38
|
+
"@zenweb/log": "^2.3.1",
|
|
38
39
|
"@zenweb/router": "^3.0.0"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|