@zenweb/schedule 2.3.4 → 2.3.5
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/register.d.ts +3 -2
- package/dist/register.js +5 -16
- package/dist/register.js.map +1 -1
- package/package.json +1 -1
package/dist/register.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/// <reference types="koa__router" />
|
|
2
2
|
import '@zenweb/router';
|
|
3
|
-
import
|
|
3
|
+
import { Middleware } from 'koa';
|
|
4
4
|
import { Core } from '@zenweb/core';
|
|
5
5
|
import { RequestCallback, ScheduleOption } from './types';
|
|
6
6
|
import { Router } from '@zenweb/router';
|
|
7
|
+
import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule';
|
|
7
8
|
export declare class ScheduleRegister {
|
|
8
9
|
option: ScheduleOption;
|
|
9
10
|
router: Router;
|
|
10
11
|
callback: RequestCallback;
|
|
11
12
|
private _index;
|
|
12
13
|
constructor(core: Core, option?: ScheduleOption);
|
|
13
|
-
job(...
|
|
14
|
+
job(rule: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number, ...middleware: Middleware[]): import("node-schedule").Job;
|
|
14
15
|
}
|
package/dist/register.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScheduleRegister = void 0;
|
|
4
4
|
require("@zenweb/router");
|
|
5
|
-
const schedule = require("node-schedule");
|
|
6
5
|
const http_1 = require("http");
|
|
6
|
+
const node_schedule_1 = require("node-schedule");
|
|
7
7
|
const SAFE_IP = '127.0.0.1';
|
|
8
8
|
/**
|
|
9
9
|
* 安全检查,防止外部调用
|
|
@@ -21,21 +21,10 @@ class ScheduleRegister {
|
|
|
21
21
|
this.callback = core.koa.callback();
|
|
22
22
|
this._index = 0;
|
|
23
23
|
}
|
|
24
|
-
job(...
|
|
25
|
-
let name = '';
|
|
26
|
-
let rule;
|
|
27
|
-
if (typeof args[1] === 'string') {
|
|
28
|
-
name = args[0];
|
|
29
|
-
rule = args[1];
|
|
30
|
-
args = args.slice(2);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
rule = args[0];
|
|
34
|
-
args = args.slice(1);
|
|
35
|
-
}
|
|
24
|
+
job(rule, ...middleware) {
|
|
36
25
|
// 注册到路由
|
|
37
|
-
const path = `/___schedule/job/${this._index++}
|
|
38
|
-
this.router.post(path, safeCheck, ...
|
|
26
|
+
const path = `/___schedule/job/${this._index++}`;
|
|
27
|
+
this.router.post(path, safeCheck, ...middleware);
|
|
39
28
|
// 注册到 scheduleJob
|
|
40
29
|
const callback = () => {
|
|
41
30
|
const request = Object.assign({
|
|
@@ -64,7 +53,7 @@ class ScheduleRegister {
|
|
|
64
53
|
this.callback(request, response);
|
|
65
54
|
}
|
|
66
55
|
};
|
|
67
|
-
return
|
|
56
|
+
return (0, node_schedule_1.scheduleJob)(rule, callback);
|
|
68
57
|
}
|
|
69
58
|
}
|
|
70
59
|
exports.ScheduleRegister = ScheduleRegister;
|
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;AAAA,0BAAwB;AACxB
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;AAAA,0BAAwB;AACxB,+BAAuD;AAKvD,iDAA2G;AAE3G,MAAM,OAAO,GAAG,WAAW,CAAC;AAE5B;;GAEG;AACH,SAAS,SAAS,CAAC,GAAY,EAAE,IAAU;IACzC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACpF,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC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