@domain.js/main 0.4.0 → 0.4.2
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/deps/cron/index.d.ts +6 -0
- package/dist/deps/cron/index.js +18 -2
- package/dist/http/socket.js +4 -3
- package/package.json +1 -1
|
@@ -21,6 +21,12 @@ interface Deps {
|
|
|
21
21
|
submit: (name: string, times: number, callback: (arg: callbackArg) => void) => void;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 定时执行函数, 解决 setTimeout 第二个参数不能大于 2147483647 的问题
|
|
26
|
+
* @param fn 要执行的函数
|
|
27
|
+
* @param timeoutMS 执行间隔时间,单位毫秒
|
|
28
|
+
*/
|
|
29
|
+
export declare const timeout: (fn: Function, timeoutMS: number) => void;
|
|
24
30
|
export declare function Main(cnf: Cnf, deps: Deps): {
|
|
25
31
|
regist: (name: string, intervalStr: string, startAt?: string | undefined) => void;
|
|
26
32
|
start: () => void;
|
package/dist/deps/cron/index.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps = exports.Main = void 0;
|
|
3
|
+
exports.Deps = exports.Main = exports.timeout = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 定时执行函数, 解决 setTimeout 第二个参数不能大于 2147483647 的问题
|
|
6
|
+
* @param fn 要执行的函数
|
|
7
|
+
* @param timeoutMS 执行间隔时间,单位毫秒
|
|
8
|
+
*/
|
|
9
|
+
const timeout = (fn, timeoutMS) => {
|
|
10
|
+
if (timeoutMS < 2147483647) {
|
|
11
|
+
setTimeout(fn, timeoutMS);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
(0, exports.timeout)(fn, timeoutMS - 2147483647);
|
|
16
|
+
}, 2147483647);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.timeout = timeout;
|
|
4
20
|
function Main(cnf, deps) {
|
|
5
21
|
const { cron = {} } = cnf;
|
|
6
22
|
const ciaTaskType = "cronJob";
|
|
@@ -37,7 +53,7 @@ function Main(cnf, deps) {
|
|
|
37
53
|
throw Error("startAt 定义不合法");
|
|
38
54
|
timeoutMS = startAt;
|
|
39
55
|
}
|
|
40
|
-
|
|
56
|
+
(0, exports.timeout)(() => {
|
|
41
57
|
opt.times += 1;
|
|
42
58
|
opt.triggeredAt = Date.now();
|
|
43
59
|
myCia.submit(`Cron::${name}`, opt.times, ({ cronJob: [err, , totalMS] }) => {
|
package/dist/http/socket.js
CHANGED
|
@@ -132,20 +132,21 @@ function BridgeSocket(io, domain) {
|
|
|
132
132
|
const method = client.methods[name];
|
|
133
133
|
try {
|
|
134
134
|
if (!method)
|
|
135
|
-
throw new MyError("notFound",
|
|
135
|
+
throw new MyError("notFound", `不存在该领域方法: ${name}`);
|
|
136
136
|
if (!client.profile)
|
|
137
137
|
throw new MyError("noAuth", "请先执行 init");
|
|
138
|
-
const res = await method(...params);
|
|
138
|
+
const res = await method(...(params || []));
|
|
139
139
|
if (responseId) {
|
|
140
140
|
client.emit("response", responseId, res);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
catch (e) {
|
|
144
144
|
if (responseId) {
|
|
145
|
+
console.error(e);
|
|
145
146
|
client.emit("responseError", responseId, e.code, e.message, e.data);
|
|
146
147
|
}
|
|
147
148
|
else {
|
|
148
|
-
client.emit(
|
|
149
|
+
client.emit("internalError", e.code, e.message, e.data);
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
return next();
|