mm_os 3.3.0 → 4.0.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/LICENSE +21 -201
- package/README.md +491 -99
- package/README_EN.md +498 -0
- package/adapter/adapter.js +431 -0
- package/adapter/custom_persistence.js +660 -0
- package/adapter/mqtt.js +273 -0
- package/adapter/socket.js +113 -0
- package/adapter/web.js +67 -0
- package/adapter/websocket.js +146 -0
- package/com/api/com.json +5 -0
- package/{core/com → com}/api/config.tpl.json +8 -8
- package/com/api/drive.js +708 -0
- package/com/api/index.js +198 -0
- package/com/api/oauth.js +200 -0
- package/com/api/script.tpl.js +32 -0
- package/com/cmd/README.md +11 -0
- package/com/cmd/com.json +5 -0
- package/com/cmd/config.tpl.json +122 -0
- package/com/cmd/drive.js +1548 -0
- package/com/cmd/index.js +1066 -0
- package/com/cmd/msg.json +48 -0
- package/com/cmd/nlp.js +525 -0
- package/com/cmd/script.tpl.js +32 -0
- package/com/db/com.json +5 -0
- package/com/db/drive.js +1999 -0
- package/com/db/index.js +242 -0
- package/com/event/com.json +5 -0
- package/{core/com → com}/event/config.tpl.json +8 -8
- package/com/event/drive.js +59 -0
- package/com/event/index.js +409 -0
- package/com/event/script.tpl.js +23 -0
- package/com/mqtt/com.json +5 -0
- package/{core/com → com}/mqtt/config.tpl.json +3 -5
- package/com/mqtt/drive.js +676 -0
- package/com/mqtt/index.js +822 -0
- package/com/mqtt/mm_mqtt.js +425 -0
- package/com/mqtt/script.tpl.js +723 -0
- package/com/nav/com.json +5 -0
- package/com/nav/config.tpl.json +84 -0
- package/com/nav/drive.js +702 -0
- package/com/nav/index.js +231 -0
- package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
- package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
- package/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/com/nav/tpl/admin_pc/page_view.vue +124 -0
- package/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/com/nav/tpl/dev_pc/page_type.vue +313 -0
- package/com/nav/tpl/home_pc/page_default.vue +234 -0
- package/com/nav/tpl/home_pc/page_form.vue +137 -0
- package/com/nav/tpl/home_pc/page_list.vue +234 -0
- package/com/nav/tpl/home_pc/page_nav.vue +221 -0
- package/com/nav/tpl/home_pc/page_type.vue +234 -0
- package/com/nav/tpl/home_pc/page_view.vue +125 -0
- package/com/nav/tpl/home_phone/page_channel.vue +234 -0
- package/com/nav/tpl/home_phone/page_default.vue +234 -0
- package/com/nav/tpl/home_phone/page_form.vue +137 -0
- package/com/nav/tpl/home_phone/page_nav.vue +237 -0
- package/com/nav/tpl/home_phone/page_type.vue +234 -0
- package/com/nav/tpl/home_phone/page_view.vue +125 -0
- package/com/nav/viewmodel.js +446 -0
- package/com/param/com.json +5 -0
- package/{core/com → com}/param/config.tpl.json +7 -1
- package/com/param/drive.js +502 -0
- package/com/param/index.js +155 -0
- package/com/param/script.tpl.js +12 -0
- package/com/pendant/com.json +5 -0
- package/{core/com/component → com/pendant}/config.tpl.json +15 -13
- package/com/pendant/drive.js +204 -0
- package/com/pendant/index.js +441 -0
- package/com/pendant/pendant.html +16 -0
- package/com/pendant/script.tpl.js +18 -0
- package/com/socket/com.json +5 -0
- package/com/socket/config.tpl.json +12 -0
- package/com/socket/drive.js +651 -0
- package/com/socket/index.js +351 -0
- package/com/socket/script.tpl.js +41 -0
- package/com/sql/com.json +5 -0
- package/{core/com → com}/sql/config.tpl.json +13 -9
- package/com/sql/drive.js +1259 -0
- package/com/sql/index.js +150 -0
- package/com/sql/script.tpl.js +47 -0
- package/com/static/com.json +5 -0
- package/{core/com → com}/static/config.tpl.json +10 -6
- package/com/static/drive.js +194 -0
- package/com/static/index.js +226 -0
- package/com/static/script.tpl.js +28 -0
- package/com/task/com.json +5 -0
- package/{core/com → com}/task/config.tpl.json +4 -6
- package/com/task/drive.js +405 -0
- package/com/task/index.js +148 -0
- package/com/task/script.tpl.js +37 -0
- package/com/template/com.json +5 -0
- package/com/template/config.tpl.json +16 -0
- package/com/template/drive.js +80 -0
- package/com/template/index.js +141 -0
- package/com.js +156 -0
- package/common/README.md +2 -0
- package/common/handler/msg/handler.json +22 -0
- package/common/handler/msg/index.js +23 -0
- package/common/handler/player/handler.json +22 -0
- package/common/handler/player/index.js +287 -0
- package/common/handler/user/handler.json +22 -0
- package/common/handler/user/index.js +23 -0
- package/common/middleware/web_after/index.js +29 -0
- package/common/middleware/web_after/middleware.json +9 -0
- package/common/middleware/web_base/index.js +113 -0
- package/common/middleware/web_base/middleware.json +19 -0
- package/common/middleware/web_before/index.js +33 -0
- package/common/middleware/web_before/middleware.json +9 -0
- package/common/middleware/web_cors/index.js +87 -0
- package/common/middleware/web_cors/middleware.json +24 -0
- package/common/middleware/web_error/index.js +119 -0
- package/common/middleware/web_error/middleware.json +18 -0
- package/common/middleware/web_ip/index.js +15 -0
- package/common/middleware/web_ip/middleware.json +14 -0
- package/common/middleware/web_logger/index.js +156 -0
- package/common/middleware/web_logger/middleware.json +14 -0
- package/common/middleware/web_main/index.js +24 -0
- package/common/middleware/web_main/middleware.json +9 -0
- package/common/middleware/web_static/index.js +73 -0
- package/common/middleware/web_static/middleware.json +54 -0
- package/common/middleware/web_waf/index.js +385 -0
- package/common/middleware/web_waf/middleware.json +13 -0
- package/common/model/msg/index.js +88 -0
- package/common/model/msg/model.json +401 -0
- package/common/model/player/index.js +63 -0
- package/common/model/player/model.json +185 -0
- package/common/model/user/index.js +11 -0
- package/common/model/user/model.json +219 -0
- package/core/app/config.tpl.json +67 -0
- package/core/app/index.js +632 -0
- package/core/app/script.tpl.js +52 -0
- package/core/channel/index.js +899 -0
- package/core/channel/matcher.js +585 -0
- package/core/com/config.tpl.json +16 -0
- package/core/com/index.js +74 -0
- package/core/com/script.tpl.js +5 -0
- package/core/component/component.js +42 -0
- package/core/component/config.tpl.json +63 -0
- package/core/component/index.js +273 -0
- package/core/component/script.tpl.js +19 -0
- package/core/controller/config.tpl.json +14 -0
- package/core/controller/index.js +373 -0
- package/core/controller/script.tpl.js +27 -0
- package/core/factory/config.tpl.json +14 -0
- package/core/factory/entity.js +275 -0
- package/core/factory/index.js +241 -0
- package/core/factory/script.tpl.js +16 -0
- package/core/game/bat/index.js +137 -0
- package/core/game/bat/world.js +622 -0
- package/core/game/config.tpl.json +16 -0
- package/core/game/entity_admin.js +230 -0
- package/core/game/index.js +186 -0
- package/core/handler/config.tpl.json +22 -0
- package/core/handler/index.js +181 -0
- package/core/handler/script.tpl.js +23 -0
- package/core/logic/config.tpl.json +14 -0
- package/core/logic/index.js +59 -0
- package/core/logic/script.tpl.js +19 -0
- package/core/middleware/config.tpl.json +16 -0
- package/core/middleware/index.js +125 -0
- package/core/middleware/script.tpl.js +37 -0
- package/core/mod/config.tpl.json +22 -0
- package/core/mod/index.js +130 -0
- package/core/mod/script.tpl.js +34 -0
- package/core/model/config.tpl.json +219 -0
- package/core/model/index.js +272 -0
- package/core/model/model.js +27 -0
- package/core/model/script.tpl.js +20 -0
- package/core/notifier/config.tpl.json +14 -0
- package/core/notifier/index.js +77 -0
- package/core/notifier/script.tpl.js +20 -0
- package/core/plugin/config.tpl.json +24 -0
- package/core/plugin/index.js +232 -0
- package/core/plugin/script.tpl.js +51 -0
- package/core/pusher/config.tpl.json +14 -0
- package/core/pusher/index.js +161 -0
- package/core/pusher/script.tpl.js +20 -0
- package/core/room/bat/index.js +170 -0
- package/core/room/bat/room.js +524 -0
- package/core/room/config.tpl.json +20 -0
- package/core/room/index.js +249 -0
- package/core/room/room.js +61 -0
- package/core/scene/config.tpl.json +14 -0
- package/core/scene/index.js +466 -0
- package/core/scene/loop.js +1255 -0
- package/core/scene/map.js +28 -0
- package/core/scene/script.tpl.js +22 -0
- package/core/sender/config.tpl.json +14 -0
- package/core/sender/index.js +79 -0
- package/core/sender/script.tpl.js +20 -0
- package/core/service/config.tpl.json +14 -0
- package/core/service/index.js +100 -0
- package/core/service/script.tpl.js +25 -0
- package/core/store/config.tpl.json +26 -0
- package/core/store/index.js +1755 -0
- package/core/store/script.tpl.js +22 -0
- package/core/store/sql.js +1464 -0
- package/core/system/config.tpl.json +18 -0
- package/core/system/index.js +312 -0
- package/core/system/script.tpl.js +77 -0
- package/core/view/config.tpl.json +14 -0
- package/core/view/index.js +91 -0
- package/core/view/script.tpl.js +20 -0
- package/core/zone/bat/index.js +725 -0
- package/core/zone/config.tpl.json +54 -0
- package/core/zone/index.js +614 -0
- package/core/zone/script.tpl.js +10 -0
- package/core/zone/zone_bat.js +136 -0
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
- package/index.js +17 -314
- package/os.js +57 -0
- package/package.json +60 -58
- package/server.js +598 -0
- package/README.en.md +0 -36
- package/conf.json +0 -3
- package/core/base/mqtt/index.js +0 -1107
- package/core/base/mqtt/lib.js +0 -40
- package/core/base/web/index.js +0 -243
- package/core/com/api/com.json +0 -4
- package/core/com/api/drive.js +0 -668
- package/core/com/api/index.js +0 -108
- package/core/com/api/oauth.js +0 -158
- package/core/com/api/script.js +0 -32
- package/core/com/app/README.md +0 -3
- package/core/com/app/com.json +0 -4
- package/core/com/app/config.tpl.json +0 -16
- package/core/com/app/drive.js +0 -309
- package/core/com/app/index.js +0 -211
- package/core/com/app/script.js +0 -155
- package/core/com/cmd/com.json +0 -4
- package/core/com/cmd/config.tpl.json +0 -66
- package/core/com/cmd/drive.js +0 -513
- package/core/com/cmd/index.js +0 -354
- package/core/com/cmd/old/5w2h.js +0 -54
- package/core/com/cmd/old/drive.js +0 -423
- package/core/com/cmd/script.js +0 -11
- package/core/com/component/README.md +0 -3
- package/core/com/component/com.json +0 -4
- package/core/com/component/component.html +0 -16
- package/core/com/component/drive.js +0 -197
- package/core/com/component/index.js +0 -312
- package/core/com/component/script.js +0 -18
- package/core/com/db/com.json +0 -4
- package/core/com/db/drive.js +0 -1160
- package/core/com/db/index.js +0 -176
- package/core/com/event/com.json +0 -4
- package/core/com/event/drive.js +0 -133
- package/core/com/event/index.js +0 -345
- package/core/com/event/script.js +0 -26
- package/core/com/eventer/com.js +0 -477
- package/core/com/eventer/com.json +0 -4
- package/core/com/middleware/com.js +0 -153
- package/core/com/middleware/com.json +0 -4
- package/core/com/middleware/config.tpl.json +0 -8
- package/core/com/middleware/script.js +0 -9
- package/core/com/mqtt/com.json +0 -4
- package/core/com/mqtt/drive.js +0 -600
- package/core/com/mqtt/index.js +0 -572
- package/core/com/mqtt/mm_mqtt.js +0 -330
- package/core/com/mqtt/script.js +0 -604
- package/core/com/msg/com.js +0 -296
- package/core/com/msg/com.json +0 -4
- package/core/com/nav/com.json +0 -4
- package/core/com/nav/config.tpl.json +0 -75
- package/core/com/nav/drive.js +0 -549
- package/core/com/nav/index.js +0 -182
- package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/core/com/nav/viewmodel.js +0 -296
- package/core/com/param/drive.js +0 -366
- package/core/com/param/index.js +0 -80
- package/core/com/param/script.js +0 -12
- package/core/com/param/test.js +0 -98
- package/core/com/plugin/README.md +0 -3
- package/core/com/plugin/com.json +0 -4
- package/core/com/plugin/config.tpl.json +0 -26
- package/core/com/plugin/drive.js +0 -536
- package/core/com/plugin/index.js +0 -259
- package/core/com/plugin/script.js +0 -213
- package/core/com/rpc/com.json +0 -4
- package/core/com/rpc/drive.js +0 -160
- package/core/com/rpc/index.js +0 -87
- package/core/com/rpc/rpc.js +0 -118
- package/core/com/socket/com.json +0 -4
- package/core/com/socket/config.tpl.json +0 -14
- package/core/com/socket/drive.js +0 -403
- package/core/com/socket/index.js +0 -62
- package/core/com/socket/script.js +0 -42
- package/core/com/sql/drive.js +0 -1087
- package/core/com/sql/index.js +0 -83
- package/core/com/sql/script.js +0 -48
- package/core/com/static/com.json +0 -4
- package/core/com/static/drive.js +0 -220
- package/core/com/static/index.js +0 -149
- package/core/com/static/script.js +0 -28
- package/core/com/task/com.json +0 -4
- package/core/com/task/drive.js +0 -403
- package/core/com/task/index.js +0 -110
- package/core/com/task/script.js +0 -37
- package/core/com/timer/com.js +0 -217
- package/core/com/timer/com.json +0 -4
- package/core/com/tpl/com.js +0 -19
- package/core/com/tpl/com.json +0 -4
- package/lib/actions.js +0 -50
- package/lib/base.js +0 -361
- package/lib/com.js +0 -29
- package/lib/ref.js +0 -121
- package/middleware/mqtt_base/index.js +0 -10
- package/middleware/mqtt_base/middleware.json +0 -10
- package/middleware/performance/index.js +0 -151
- package/middleware/performance/middleware.json +0 -16
- package/middleware/security_audit/index.js +0 -549
- package/middleware/security_audit/middleware.json +0 -48
- package/middleware/security_headers/index.js +0 -487
- package/middleware/security_headers/middleware.json +0 -45
- package/middleware/waf/index.js +0 -348
- package/middleware/waf/middleware.json +0 -10
- package/middleware/waf_ddos/index.js +0 -520
- package/middleware/waf_ddos/middleware.json +0 -38
- package/middleware/waf_ip/index.js +0 -379
- package/middleware/waf_ip/middleware.json +0 -49
- package/middleware/waf_xss/index.js +0 -269
- package/middleware/waf_xss/middleware.json +0 -18
- package/middleware/web_after/index.js +0 -33
- package/middleware/web_after/middleware.json +0 -9
- package/middleware/web_base/index.js +0 -90
- package/middleware/web_base/middleware.json +0 -9
- package/middleware/web_before/index.js +0 -27
- package/middleware/web_before/middleware.json +0 -9
- package/middleware/web_check/index.js +0 -28
- package/middleware/web_check/middleware.json +0 -9
- package/middleware/web_main/index.js +0 -28
- package/middleware/web_main/middleware.json +0 -9
- package/middleware/web_proxy/index.js +0 -37
- package/middleware/web_proxy/middleware.json +0 -9
- package/middleware/web_render/index.js +0 -87
- package/middleware/web_render/middleware.json +0 -9
- package/middleware/web_socket/index.js +0 -34
- package/middleware/web_socket/middleware.json +0 -9
- package/middleware/web_static/index.js +0 -115
- package/middleware/web_static/middleware.json +0 -9
- /package/{core/com → com}/api/README.md +0 -0
- /package/{core/com → com}/db/README.md +0 -0
- /package/{core/com → com}/event/README.md +0 -0
- /package/{core/com → com}/mqtt/README.md +0 -0
- /package/{core/com → com}/nav/README.md +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
- /package/{core/com → com}/param/README.md +0 -0
- /package/{core/com/cmd → com/pendant}/README.md +0 -0
- /package/{core/com → com}/socket/README.md +0 -0
- /package/{core/com → com}/sql/README.md +0 -0
- /package/{core/com → com}/static/README.md +0 -0
- /package/{core/com → com}/task/README.md +0 -0
package/core/com/task/drive.js
DELETED
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
const Item = require('mm_machine').Item;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 延迟
|
|
5
|
-
* @param {Number} 毫秒
|
|
6
|
-
*/
|
|
7
|
-
function sleep(milliSeconds) {
|
|
8
|
-
var endTime = new Date().getTime() + milliSeconds;
|
|
9
|
-
while (new Date().getTime() < endTime) {}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 计算时间差
|
|
14
|
-
* @param {String} startTime 开始时间
|
|
15
|
-
* @param {String} endTime 结束时间
|
|
16
|
-
* @return {Number} 返回间隔时长
|
|
17
|
-
*/
|
|
18
|
-
function span(startTime, endTime) {
|
|
19
|
-
var stime = Date.parse(startTime);
|
|
20
|
-
var etime = Date.parse(endTime);
|
|
21
|
-
return etime - stime;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 转为时间
|
|
26
|
-
* @param {String} timeStr 时间字符串
|
|
27
|
-
* @return {Date} 时间类型
|
|
28
|
-
*/
|
|
29
|
-
function toTime(timeStr) {
|
|
30
|
-
var str = timeStr.replace('T', ' ').replace('Z', '').replaceAll('.', '/').replaceAll('-', '/');
|
|
31
|
-
return new Date(str);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 定时器类函数
|
|
36
|
-
*/
|
|
37
|
-
class Drive extends Item {
|
|
38
|
-
/**
|
|
39
|
-
* 构造函数
|
|
40
|
-
* @param {String} dir 当前目录
|
|
41
|
-
*/
|
|
42
|
-
constructor(dir) {
|
|
43
|
-
super(dir, __dirname);
|
|
44
|
-
this.default_file = "./task.json";
|
|
45
|
-
|
|
46
|
-
// 更新配置并重载脚本
|
|
47
|
-
this.mode = 3;
|
|
48
|
-
|
|
49
|
-
/// 配置参数
|
|
50
|
-
this.config = {
|
|
51
|
-
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
52
|
-
"name": "demo",
|
|
53
|
-
// 状态 0未启用,1启用
|
|
54
|
-
"state": 1,
|
|
55
|
-
// 标题, 介绍事件作用
|
|
56
|
-
"title": "示例事件",
|
|
57
|
-
// 描述, 用于描述该事件有什么用的
|
|
58
|
-
"description": "描述事件使用方法",
|
|
59
|
-
// 文件路径, 当调用函数不存在时,会先从文件中加载
|
|
60
|
-
"func_file": "./index.js",
|
|
61
|
-
// 执行次数
|
|
62
|
-
"num": 10,
|
|
63
|
-
// 时间间隔(毫秒ms)
|
|
64
|
-
"interval": 1000,
|
|
65
|
-
// 等待时长(毫秒ms)
|
|
66
|
-
"wait": 0,
|
|
67
|
-
// 执行时间
|
|
68
|
-
"time": "",
|
|
69
|
-
// 执行开始日期
|
|
70
|
-
"date_start": "",
|
|
71
|
-
// 执行结束日期
|
|
72
|
-
"date_end": "",
|
|
73
|
-
// 执行顺序
|
|
74
|
-
"sort": 100
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/// 状态
|
|
78
|
-
this.state = "start";
|
|
79
|
-
/// 等候器
|
|
80
|
-
this.timeout;
|
|
81
|
-
/// 定时执行器
|
|
82
|
-
this.interval;
|
|
83
|
-
/// 当前执行次数
|
|
84
|
-
this.num = 1;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @description 设置等待执行
|
|
90
|
-
* @param {Function} func 回调函数
|
|
91
|
-
*/
|
|
92
|
-
Drive.prototype.setTimeout = function(func) {
|
|
93
|
-
if (!func) {
|
|
94
|
-
func = function() {};
|
|
95
|
-
}
|
|
96
|
-
this.timeout = setTimeout(func, this.config.wait);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @description 设置间隔执行
|
|
101
|
-
* @param {Function} func 回调函数
|
|
102
|
-
*/
|
|
103
|
-
Drive.prototype.setInterval = async function(func) {
|
|
104
|
-
if (!func) {
|
|
105
|
-
func = function() {};
|
|
106
|
-
}
|
|
107
|
-
sleep(this.config.wait);
|
|
108
|
-
this.interval = setInterval(func, this.config.interval);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @description 设置时期执行
|
|
113
|
-
* @param {Function} func 回调函数
|
|
114
|
-
*/
|
|
115
|
-
Drive.prototype.setPeriod = function(func) {
|
|
116
|
-
var _this = this;
|
|
117
|
-
var cg = this.config;
|
|
118
|
-
var fn;
|
|
119
|
-
var time = cg.time;
|
|
120
|
-
if (time) {
|
|
121
|
-
if (time.indexOf(' ') !== -1) {
|
|
122
|
-
if (time.indexOf('-') !== -1) {
|
|
123
|
-
var arr = time.split('-');
|
|
124
|
-
if (arr.length > 2) {
|
|
125
|
-
fn = function() {
|
|
126
|
-
if (new Date().toStr('yyyy-MM-dd hh:mm:ss') === time) {
|
|
127
|
-
func();
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
} else {
|
|
131
|
-
fn = function() {
|
|
132
|
-
if (new Date().toStr('MM-dd hh:mm:ss') === time) {
|
|
133
|
-
func();
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
var arr = time.split(':');
|
|
139
|
-
if (arr.length == 3) {
|
|
140
|
-
fn = function() {
|
|
141
|
-
if (new Date().toStr('dd hh:mm:ss') === time) {
|
|
142
|
-
func();
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
} else if (arr.length == 2) {
|
|
146
|
-
fn = function() {
|
|
147
|
-
if (new Date().toStr('dd hh:mm') === time) {
|
|
148
|
-
func();
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
} else {
|
|
152
|
-
fn = function() {
|
|
153
|
-
if (new Date().toStr('dd hh') === time) {
|
|
154
|
-
func();
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
var arr = time.split(':');
|
|
161
|
-
if (arr.length == 3) {
|
|
162
|
-
fn = function() {
|
|
163
|
-
if (new Date().toStr('hh:mm:ss') === time) {
|
|
164
|
-
func();
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
} else if (arr.length == 2) {
|
|
168
|
-
fn = function() {
|
|
169
|
-
if (new Date().toStr('hh:mm') === time) {
|
|
170
|
-
func();
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
} else {
|
|
174
|
-
fn = function() {
|
|
175
|
-
if (new Date().toStr('mm') === time) {
|
|
176
|
-
func();
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
} else {
|
|
182
|
-
fn = func;
|
|
183
|
-
}
|
|
184
|
-
if (cg.date_start) {
|
|
185
|
-
var start = toTime(cg.date_start);
|
|
186
|
-
if (cg.date_end) {
|
|
187
|
-
var end = toTime(cg.date_end);
|
|
188
|
-
return function() {
|
|
189
|
-
var now = new Date();
|
|
190
|
-
if (span(now, end) >= 0) {
|
|
191
|
-
if (span(now, start) <= 0) {
|
|
192
|
-
fn();
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
_this.clear_sub();
|
|
196
|
-
_this.notify(_this.config.name, 'time_end');
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
} else {
|
|
200
|
-
return function() {
|
|
201
|
-
var now = new Date();
|
|
202
|
-
if (span(now, start) <= 0) {
|
|
203
|
-
fn();
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
} else if (cg.date_end) {
|
|
208
|
-
var end = toTime(cg.date_end);
|
|
209
|
-
return function() {
|
|
210
|
-
var now = new Date();
|
|
211
|
-
if (span(now, end) >= 0) {
|
|
212
|
-
fn();
|
|
213
|
-
} else {
|
|
214
|
-
_this.clear_sub();
|
|
215
|
-
_this.notify(_this.config.name, 'time_end');
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
} else {
|
|
219
|
-
return fn;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* @description 设置按次数执行
|
|
225
|
-
* @param {Function} func 回调函数
|
|
226
|
-
*/
|
|
227
|
-
Drive.prototype.setNum = function(func) {
|
|
228
|
-
var _this = this;
|
|
229
|
-
return function() {
|
|
230
|
-
if (_this.state === 'start') {
|
|
231
|
-
try {
|
|
232
|
-
if (_this.config.num < 1) {
|
|
233
|
-
func();
|
|
234
|
-
} else if (_this.num < _this.config.num) {
|
|
235
|
-
func();
|
|
236
|
-
_this.num += 1;
|
|
237
|
-
} else {
|
|
238
|
-
func();
|
|
239
|
-
_this.clear();
|
|
240
|
-
_this.notify(_this.config.name, 'completed');
|
|
241
|
-
}
|
|
242
|
-
} catch (err) {
|
|
243
|
-
$.log.error("定时任务执行失败!", _this.config.name, err);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* @description 结束定时器
|
|
251
|
-
*/
|
|
252
|
-
Drive.prototype.end = function() {
|
|
253
|
-
// 当前状态为结束
|
|
254
|
-
this.state = "end";
|
|
255
|
-
this.notify(this.config.name, 'suspend');
|
|
256
|
-
this.clear();
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* @description 清除定时器(子函数)
|
|
261
|
-
*/
|
|
262
|
-
Drive.prototype.clear_sub = function() {
|
|
263
|
-
if (this.interval) {
|
|
264
|
-
clearInterval(this.interval);
|
|
265
|
-
}
|
|
266
|
-
if (this.timeout) {
|
|
267
|
-
clearTimeout(this.timeout);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @description 清除定时器
|
|
273
|
-
* @param {Number} millisecond 时间间隔, 单位: 毫秒
|
|
274
|
-
*/
|
|
275
|
-
Drive.prototype.clear = function(millisecond) {
|
|
276
|
-
if (millisecond) {
|
|
277
|
-
var _this = this;
|
|
278
|
-
setTimeout(function() {
|
|
279
|
-
_this.clear_sub();
|
|
280
|
-
}, millisecond);
|
|
281
|
-
} else {
|
|
282
|
-
this.clear_sub();
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* @description 执行线程
|
|
288
|
-
* @param {Function} func 回调函数
|
|
289
|
-
* @return {Object} 当前类
|
|
290
|
-
*/
|
|
291
|
-
Drive.prototype.main = async function() {
|
|
292
|
-
$.log.debug('定时任务(默认), 执行中...');
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* @description 执行线程
|
|
297
|
-
* @param {Function} func 回调函数
|
|
298
|
-
* @return {Object} 当前类
|
|
299
|
-
*/
|
|
300
|
-
Drive.prototype.run = async function(func) {
|
|
301
|
-
this.init();
|
|
302
|
-
if (func) {
|
|
303
|
-
await this.setInterval(this.setPeriod(this.setNum(func)));
|
|
304
|
-
} else {
|
|
305
|
-
await this.setInterval(this.setPeriod(this.setNum(() => {
|
|
306
|
-
this.main();
|
|
307
|
-
})));
|
|
308
|
-
}
|
|
309
|
-
return this;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* @description 初始化定时器
|
|
314
|
-
*/
|
|
315
|
-
Drive.prototype.init = function() {
|
|
316
|
-
// 当前执行次数
|
|
317
|
-
this.num = 1;
|
|
318
|
-
// 当前状态为开启
|
|
319
|
-
this.state = "start";
|
|
320
|
-
this.notify(this.config.name, 'init');
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* @description 启动定时器
|
|
325
|
-
*/
|
|
326
|
-
Drive.prototype.start = function() {
|
|
327
|
-
// 当前状态为开启
|
|
328
|
-
this.state = "start";
|
|
329
|
-
this.notify(this.config.name, 'start');
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* @description 暂停定时器
|
|
334
|
-
*/
|
|
335
|
-
Drive.prototype.stop = function() {
|
|
336
|
-
// 当前状态为开启
|
|
337
|
-
this.state = "stop";
|
|
338
|
-
this.notify(this.config.name, 'stop');
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* @description 通知函数, 当定时器执行完最后一次时, 会调用通知函数
|
|
343
|
-
* @param {String} name 名称
|
|
344
|
-
* @param {String} state 状态
|
|
345
|
-
*/
|
|
346
|
-
Drive.prototype.notify = function(name, state) {
|
|
347
|
-
// switch (state) {
|
|
348
|
-
// case "init":
|
|
349
|
-
// $.log.debug('初始化');
|
|
350
|
-
// break;
|
|
351
|
-
// case "start":
|
|
352
|
-
// $.log.debug('开始执行');
|
|
353
|
-
// break;
|
|
354
|
-
// case "stop":
|
|
355
|
-
// $.log.debug('已暂停');
|
|
356
|
-
// break;
|
|
357
|
-
// case "suspend":
|
|
358
|
-
// // 主动中断
|
|
359
|
-
// $.log.debug('已中断');
|
|
360
|
-
// break;
|
|
361
|
-
// case "time_end":
|
|
362
|
-
// $.log.debug('已到期');
|
|
363
|
-
// break;
|
|
364
|
-
// case "completed":
|
|
365
|
-
// $.log.debug('已完成');
|
|
366
|
-
// break;
|
|
367
|
-
// default:
|
|
368
|
-
// break;
|
|
369
|
-
// }
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* @description 销毁资源
|
|
374
|
-
*/
|
|
375
|
-
Drive.prototype.dispose = function() {
|
|
376
|
-
this.clear_sub();
|
|
377
|
-
this.interval = undefined;
|
|
378
|
-
this.timeout = undefined;
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* 获取插件
|
|
383
|
-
* @param {String} app 应用名称
|
|
384
|
-
* @param {String} name 插件名称
|
|
385
|
-
* @returns {Object} 返回获取到的插件
|
|
386
|
-
*/
|
|
387
|
-
Drive.prototype.plugin = function(app, name) {
|
|
388
|
-
var plus;
|
|
389
|
-
var l = $.slash;
|
|
390
|
-
if (!app) {
|
|
391
|
-
app = this.filename.between("app" + l, l);
|
|
392
|
-
}
|
|
393
|
-
if (!name) {
|
|
394
|
-
name = this.filename.between("plugin" + l, l);
|
|
395
|
-
}
|
|
396
|
-
var plugins = $.pool.plugin[app];
|
|
397
|
-
if (plugins) {
|
|
398
|
-
plus = plugins.get(name);
|
|
399
|
-
}
|
|
400
|
-
return plus
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
module.exports = Drive;
|
package/core/com/task/index.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
const Index = require('mm_machine').Index;
|
|
2
|
-
const Drive = require('./drive');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 任务类
|
|
6
|
-
* @extends {Index}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Task extends Index {
|
|
10
|
-
/**
|
|
11
|
-
* 构造函数
|
|
12
|
-
* @param {Object} scope 作用域
|
|
13
|
-
* @param {String} title 标题
|
|
14
|
-
* @constructor
|
|
15
|
-
*/
|
|
16
|
-
constructor(scope, title) {
|
|
17
|
-
super(scope, __dirname);
|
|
18
|
-
this.Drive = Drive;
|
|
19
|
-
this.type = "task";
|
|
20
|
-
this.title = title;
|
|
21
|
-
// 更新配置并重载脚本
|
|
22
|
-
this.mode = 3;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 执行任务
|
|
28
|
-
* @param {String} name 要执行的名称
|
|
29
|
-
*/
|
|
30
|
-
Task.prototype.run = async function(name) {
|
|
31
|
-
var lt = this.list;
|
|
32
|
-
if (name) {
|
|
33
|
-
for (var i = 0, o; o = lt[i++];) {
|
|
34
|
-
if (o.config.state === 1 && o.config.name === name) {
|
|
35
|
-
try {
|
|
36
|
-
await o.run();
|
|
37
|
-
} catch (error) {
|
|
38
|
-
$.log.error("定时任务错误", o.name, error);
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
for (var i = 0, o; o = lt[i++];) {
|
|
45
|
-
if (o.config.state === 1) {
|
|
46
|
-
try {
|
|
47
|
-
await o.run();
|
|
48
|
-
} catch (error) {
|
|
49
|
-
$.log.error("定时任务错误", o.name, error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 加载项
|
|
58
|
-
* @param {String} dir 文件路径
|
|
59
|
-
* @param {Object} cg 配置参数
|
|
60
|
-
* @param {String} file 配置文件
|
|
61
|
-
*/
|
|
62
|
-
Task.prototype.load_item = async function(dir, cg, file) {
|
|
63
|
-
var _this = this;
|
|
64
|
-
var drive = new this.Drive(dir, this.dir_base.fullname());
|
|
65
|
-
drive.mode = this.mode;
|
|
66
|
-
if (cg) {
|
|
67
|
-
await drive.exec('load_config', file, cg.name);
|
|
68
|
-
await drive.exec('set_config', cg);
|
|
69
|
-
} else {
|
|
70
|
-
await drive.exec('load_config', file);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
drive.admin = function() {
|
|
74
|
-
return _this;
|
|
75
|
-
};
|
|
76
|
-
this.list.push(drive);
|
|
77
|
-
return drive;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
exports.Task = Task;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Task模板池
|
|
84
|
-
*/
|
|
85
|
-
if (!$.pool.task) {
|
|
86
|
-
$.pool.task = {};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Task管理器,用于创建缓存
|
|
91
|
-
* @task {String} scope 作用域
|
|
92
|
-
* @param {string} title 标题
|
|
93
|
-
* @return {Object} 返回一个缓存类
|
|
94
|
-
*/
|
|
95
|
-
function task_admin(scope, title) {
|
|
96
|
-
if (!scope) {
|
|
97
|
-
scope = $.val.scope + '';
|
|
98
|
-
}
|
|
99
|
-
var obj = $.pool.task[scope];
|
|
100
|
-
if (!obj) {
|
|
101
|
-
$.pool.task[scope] = new Task(scope, title);
|
|
102
|
-
obj = $.pool.task[scope];
|
|
103
|
-
}
|
|
104
|
-
return obj;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @module 导出Task管理器
|
|
109
|
-
*/
|
|
110
|
-
$.task_admin = task_admin;
|
package/core/com/task/script.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 定时任务函数
|
|
3
|
-
*/
|
|
4
|
-
exports.main = async function main() {
|
|
5
|
-
$.log.debug('定时任务, 执行中...');
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 执行结果通知
|
|
10
|
-
* @param {String} name 任务名称
|
|
11
|
-
* @param {String} state 状态
|
|
12
|
-
*/
|
|
13
|
-
exports.notify = async function(name, state) {
|
|
14
|
-
switch (state) {
|
|
15
|
-
case "init":
|
|
16
|
-
$.log.debug('任务-初始化');
|
|
17
|
-
break;
|
|
18
|
-
case "start":
|
|
19
|
-
$.log.debug('任务-开始执行');
|
|
20
|
-
break;
|
|
21
|
-
case "stop":
|
|
22
|
-
$.log.debug('任务-已暂停');
|
|
23
|
-
break;
|
|
24
|
-
case "suspend":
|
|
25
|
-
// 主动中断
|
|
26
|
-
$.log.debug('任务-已中断');
|
|
27
|
-
break;
|
|
28
|
-
case "time_end":
|
|
29
|
-
$.log.debug('任务-已到期');
|
|
30
|
-
break;
|
|
31
|
-
case "completed":
|
|
32
|
-
$.log.debug('任务-已完成');
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
};
|