@pisell/core 1.0.0 → 1.0.1
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/es/app/app.d.ts +122 -0
- package/es/app/app.js +166 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +54 -0
- package/es/applicationManager/application.d.ts +50 -0
- package/es/applicationManager/application.js +226 -0
- package/es/applicationManager/index.d.ts +13 -0
- package/es/applicationManager/index.js +190 -0
- package/es/config.d.ts +3 -3
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +29 -0
- package/es/data/index.js +8 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +20 -0
- package/es/history/index.js +41 -0
- package/es/history/type.d.ts +2 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +7 -1
- package/es/index.js +8 -2
- package/es/indexDB/index.d.ts +176 -0
- package/es/indexDB/index.js +536 -0
- package/es/locales/config.js +10 -8
- package/es/locales/en.d.ts +2 -1
- package/es/locales/en.js +5 -1
- package/es/locales/index.d.ts +44 -1
- package/es/locales/index.js +192 -8
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +15 -5
- package/es/locales/zh-CN.d.ts +2 -1
- package/es/locales/zh-CN.js +5 -1
- package/es/locales/zh-HK.d.ts +2 -1
- package/es/locales/zh-HK.js +5 -1
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +122 -0
- package/es/logger/index.js +531 -0
- package/es/menuManager/hooks.d.ts +8 -0
- package/es/menuManager/hooks.js +138 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +142 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +65 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +66 -0
- package/es/models/tasks.d.ts +31 -0
- package/es/models/tasks.js +331 -0
- package/es/models/tasksUtils.d.ts +65 -0
- package/es/models/tasksUtils.js +179 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +63 -0
- package/es/pubsub/index.js +144 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +310 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +58 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +175 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +40 -0
- package/es/request/type.js +1 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +145 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +154 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +692 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +185 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +438 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +129 -0
- package/es/socket/socket.js +597 -0
- package/es/socket/types.d.ts +84 -0
- package/es/socket/types.js +19 -0
- package/es/storage/config.d.ts +3 -0
- package/es/{date → storage}/config.js +1 -6
- package/es/storage/index.d.ts +42 -0
- package/es/storage/index.js +62 -0
- package/es/storage/type.d.ts +5 -0
- package/es/storage/type.js +1 -0
- package/es/tasks/index.d.ts +77 -0
- package/es/tasks/index.js +719 -0
- package/es/tasks/type.d.ts +62 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +4 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +1 -1
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +14 -0
- package/es/variables/config.d.ts +3 -0
- package/es/{date/index.js → variables/config.js} +8 -14
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +122 -0
- package/lib/app/app.js +128 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +50 -0
- package/lib/applicationManager/application.js +110 -0
- package/lib/applicationManager/index.d.ts +13 -0
- package/lib/applicationManager/index.js +76 -0
- package/lib/config.d.ts +3 -3
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +64 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +29 -0
- package/lib/{date → data}/index.js +19 -20
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +20 -0
- package/lib/history/index.js +58 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/index.js +44 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +7 -1
- package/lib/index.js +23 -5
- package/lib/indexDB/index.d.ts +176 -0
- package/lib/indexDB/index.js +287 -0
- package/lib/locales/config.js +10 -7
- package/lib/locales/en.d.ts +2 -1
- package/lib/locales/en.js +5 -1
- package/lib/locales/index.d.ts +44 -1
- package/lib/locales/index.js +106 -4
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +15 -5
- package/lib/locales/zh-CN.d.ts +2 -1
- package/lib/locales/zh-CN.js +5 -1
- package/lib/locales/zh-HK.d.ts +2 -1
- package/lib/locales/zh-HK.js +5 -1
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +122 -0
- package/lib/logger/index.js +288 -0
- package/lib/menuManager/hooks.d.ts +8 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +110 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +70 -0
- package/lib/models/tasks.d.ts +31 -0
- package/lib/models/tasks.js +199 -0
- package/lib/models/tasksUtils.d.ts +65 -0
- package/lib/models/tasksUtils.js +160 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +63 -0
- package/lib/pubsub/index.js +129 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +159 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +74 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +143 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +40 -0
- package/lib/request/type.js +17 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +111 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +118 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +346 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +152 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +200 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +346 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +153 -0
- package/lib/socket/socket.d.ts +129 -0
- package/lib/socket/socket.js +410 -0
- package/lib/socket/types.d.ts +84 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/config.d.ts +3 -0
- package/lib/{date → storage}/config.js +2 -7
- package/lib/storage/index.d.ts +42 -0
- package/lib/storage/index.js +66 -0
- package/lib/storage/type.d.ts +5 -0
- package/lib/storage/type.js +17 -0
- package/lib/tasks/index.d.ts +77 -0
- package/lib/tasks/index.js +438 -0
- package/lib/tasks/type.d.ts +62 -0
- package/lib/{date → tasks}/type.js +1 -1
- package/lib/tasks/useTasks.d.ts +4 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +1 -1
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/VariablesProvider.js +51 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/config.js +38 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- package/package.json +13 -3
- package/es/date/config.d.ts +0 -3
- package/es/date/index.d.ts +0 -7
- package/es/date/type.d.ts +0 -7
- package/lib/date/config.d.ts +0 -3
- package/lib/date/index.d.ts +0 -7
- package/lib/date/type.d.ts +0 -7
- /package/es/{date → history}/type.js +0 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/tasks/index.ts
|
|
30
|
+
var tasks_exports = {};
|
|
31
|
+
__export(tasks_exports, {
|
|
32
|
+
TasksManager: () => TasksManager
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(tasks_exports);
|
|
35
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
36
|
+
var import_utils = require("@pisell/utils");
|
|
37
|
+
var import_useTasks = __toESM(require("./useTasks"));
|
|
38
|
+
var TasksManager = class {
|
|
39
|
+
constructor(app) {
|
|
40
|
+
this.useTasks = import_useTasks.default;
|
|
41
|
+
this.watchTaskCallback = () => {
|
|
42
|
+
};
|
|
43
|
+
// 将任务队列状态同步到 local
|
|
44
|
+
this.saveTaskQueueToLocal = async (state) => {
|
|
45
|
+
var _a;
|
|
46
|
+
console.log("saveTaskQueueToLocal", state);
|
|
47
|
+
let tasksData = await this.db.get("tasks", "tasks");
|
|
48
|
+
const newData = { id: "tasks", ...state };
|
|
49
|
+
if (!tasksData) {
|
|
50
|
+
await this.db.add("tasks", newData);
|
|
51
|
+
} else {
|
|
52
|
+
await this.db.update("tasks", newData);
|
|
53
|
+
}
|
|
54
|
+
(_a = this.watchTaskCallback) == null ? void 0 : _a.call(this, this.tasks);
|
|
55
|
+
};
|
|
56
|
+
// 从 local 加载任务队列状态
|
|
57
|
+
this.loadTaskQueueFromLocal = async () => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
try {
|
|
60
|
+
const tasks = await this.db.get("tasks", "tasks");
|
|
61
|
+
for (let module2 in tasks) {
|
|
62
|
+
for (let queueId in tasks[module2]) {
|
|
63
|
+
for (let task of ((_b = (_a = tasks == null ? void 0 : tasks[module2]) == null ? void 0 : _a[queueId]) == null ? void 0 : _b.tasks) || []) {
|
|
64
|
+
if (task.destroy) {
|
|
65
|
+
delete tasks[module2][queueId].tasks;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return tasks;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.log("loadTaskQueueFromLocal", err);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @title: 执行任务
|
|
78
|
+
* @description:
|
|
79
|
+
* @param {Task} task
|
|
80
|
+
* @return {*}
|
|
81
|
+
* @Author: zhiwei.Wang
|
|
82
|
+
* @Date: 2024-09-26 13:53
|
|
83
|
+
*/
|
|
84
|
+
this.runTask = async (task) => {
|
|
85
|
+
const beforeAction = this.getTaskFunction(task.beforeAction || "");
|
|
86
|
+
const afterAction = this.getTaskFunction(task.afterAction || "");
|
|
87
|
+
const action = this.getTaskFunction(task.action || "");
|
|
88
|
+
let beforeActionRes;
|
|
89
|
+
let afterActionRes;
|
|
90
|
+
let actionRes = { status: "success" };
|
|
91
|
+
try {
|
|
92
|
+
if (beforeAction) {
|
|
93
|
+
beforeActionRes = await beforeAction({ task });
|
|
94
|
+
}
|
|
95
|
+
if (action) {
|
|
96
|
+
actionRes = await action({ task, beforeActionRes });
|
|
97
|
+
}
|
|
98
|
+
if (afterAction) {
|
|
99
|
+
afterActionRes = await afterAction({ task, actionRes, afterActionRes });
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this.app.logger.addLog({
|
|
103
|
+
type: "error",
|
|
104
|
+
title: `任务执行失败-${task.id}`,
|
|
105
|
+
metadata: { error, taskPayload: task == null ? void 0 : task.payload }
|
|
106
|
+
});
|
|
107
|
+
console.log("任务执行失败", error);
|
|
108
|
+
actionRes = { status: "failure" };
|
|
109
|
+
}
|
|
110
|
+
console.log("Tasks--->", `任务执行成功: ${task.id}`);
|
|
111
|
+
return actionRes;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* @title: 启动轮询
|
|
115
|
+
* @description: 根据轮询间隔定期执行任务
|
|
116
|
+
* @param {Task} task
|
|
117
|
+
* @return {*}
|
|
118
|
+
*/
|
|
119
|
+
this.startPolling = (task) => {
|
|
120
|
+
if (!task.polling || !task.polling.interval) {
|
|
121
|
+
console.log("不是轮询任务");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const timerId = setTimeout(async () => {
|
|
125
|
+
var _a;
|
|
126
|
+
try {
|
|
127
|
+
await this.runTask(task);
|
|
128
|
+
console.log("轮询任务", task);
|
|
129
|
+
let _task = { ...task };
|
|
130
|
+
_task.pollingResult = {
|
|
131
|
+
count: (((_a = _task.pollingResult) == null ? void 0 : _a.count) || 0) + 1,
|
|
132
|
+
timerId
|
|
133
|
+
};
|
|
134
|
+
const newTask = this.updateTask({
|
|
135
|
+
module: task.module,
|
|
136
|
+
queueId: task.queueId,
|
|
137
|
+
taskId: task.id,
|
|
138
|
+
other: _task
|
|
139
|
+
});
|
|
140
|
+
if (!newTask) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.startPolling(newTask);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
clearTimeout(timerId);
|
|
146
|
+
console.error("轮询任务异常", error);
|
|
147
|
+
}
|
|
148
|
+
}, task.polling.interval);
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* @title: 创建任务数据
|
|
152
|
+
* @description:
|
|
153
|
+
* @param {Partial} payload
|
|
154
|
+
* @return {*}
|
|
155
|
+
* @Author: zhiwei.Wang
|
|
156
|
+
* @Date: 2024-09-26 13:54
|
|
157
|
+
*/
|
|
158
|
+
this.createTaskData = (payload) => {
|
|
159
|
+
return {
|
|
160
|
+
id: (0, import_utils.getUniqueId)("task_"),
|
|
161
|
+
create_at: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
|
|
162
|
+
type: "local",
|
|
163
|
+
retries: 0,
|
|
164
|
+
maxRetries: 3,
|
|
165
|
+
status: "pending",
|
|
166
|
+
// 执行函数
|
|
167
|
+
action: "",
|
|
168
|
+
// 执行参数
|
|
169
|
+
payload: {},
|
|
170
|
+
// 执行前的钩子
|
|
171
|
+
beforeAction: "",
|
|
172
|
+
// 执行前的参数
|
|
173
|
+
beforePayload: {},
|
|
174
|
+
// 执行后的钩子
|
|
175
|
+
afterAction: "",
|
|
176
|
+
// 执行后的参数
|
|
177
|
+
afterPayload: {},
|
|
178
|
+
destroy: true,
|
|
179
|
+
...payload
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
this.getTaskQueue = (payload) => {
|
|
183
|
+
const { queueId, module: module2 } = payload;
|
|
184
|
+
return this.tasks[module2][queueId].tasks;
|
|
185
|
+
};
|
|
186
|
+
this.timeout = (ms) => {
|
|
187
|
+
return new Promise((resolve) => {
|
|
188
|
+
setTimeout(() => {
|
|
189
|
+
resolve(true);
|
|
190
|
+
}, ms || 5e3);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
if (!app) {
|
|
194
|
+
throw new Error("app is required");
|
|
195
|
+
}
|
|
196
|
+
this.app = app;
|
|
197
|
+
this.taskFunctions = /* @__PURE__ */ new Map();
|
|
198
|
+
this.tasks = {};
|
|
199
|
+
this.db = app.dbManager;
|
|
200
|
+
}
|
|
201
|
+
// 单例模式
|
|
202
|
+
static getInstance(app) {
|
|
203
|
+
if (!TasksManager.instance && app) {
|
|
204
|
+
TasksManager.instance = new TasksManager(app);
|
|
205
|
+
}
|
|
206
|
+
return TasksManager.instance;
|
|
207
|
+
}
|
|
208
|
+
// 注册任务函数
|
|
209
|
+
addTaskFunction(name, fun) {
|
|
210
|
+
this.taskFunctions.set(name, fun);
|
|
211
|
+
console.log("Tasks--->", `注册任务函数成功: ${name}`);
|
|
212
|
+
}
|
|
213
|
+
// 注册任务函数列表
|
|
214
|
+
addTaskFunctions(tasks) {
|
|
215
|
+
tasks.forEach(({ name, fun }) => {
|
|
216
|
+
this.taskFunctions.set(name, fun);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
getTasks() {
|
|
220
|
+
return this.tasks;
|
|
221
|
+
}
|
|
222
|
+
// 获取任务函数
|
|
223
|
+
getTaskFunction(name) {
|
|
224
|
+
if (!name) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return this.taskFunctions.get(name);
|
|
228
|
+
}
|
|
229
|
+
// 初始化任务
|
|
230
|
+
async init() {
|
|
231
|
+
const tasks = await this.loadTaskQueueFromLocal();
|
|
232
|
+
if (tasks) {
|
|
233
|
+
console.log("initTasks", tasks);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* @title: 执行任务队列
|
|
238
|
+
* @description:
|
|
239
|
+
* @return {*}
|
|
240
|
+
* @Author: zhiwei.Wang
|
|
241
|
+
* @Date: 2024-09-26 13:52
|
|
242
|
+
*/
|
|
243
|
+
async run(payload) {
|
|
244
|
+
var _a, _b;
|
|
245
|
+
const { queueId, module: module2, callback } = payload;
|
|
246
|
+
let taskQueueStatus = "";
|
|
247
|
+
while (taskQueueStatus !== "completed") {
|
|
248
|
+
const taskQueue = this.getTaskQueue(payload);
|
|
249
|
+
const errorTaskIds = [];
|
|
250
|
+
if (taskQueue && taskQueue.length) {
|
|
251
|
+
const tasksToExecute = taskQueue.filter(
|
|
252
|
+
(task) => (task == null ? void 0 : task.status) === "pending" || (task == null ? void 0 : task.status) === "failure"
|
|
253
|
+
);
|
|
254
|
+
console.log("Tasks--->", "需要执行的任务", tasksToExecute);
|
|
255
|
+
for (let task of tasksToExecute) {
|
|
256
|
+
try {
|
|
257
|
+
if (task.retries !== void 0 && task.maxRetries !== void 0 && task.retries < task.maxRetries) {
|
|
258
|
+
task.status = "in-progress";
|
|
259
|
+
this.updateTask({ module: module2, queueId, taskId: task.id, other: { status: task.status } });
|
|
260
|
+
if (task.polling) {
|
|
261
|
+
this.startPolling(task);
|
|
262
|
+
} else {
|
|
263
|
+
const { status } = await this.runTask(task);
|
|
264
|
+
task.status = status;
|
|
265
|
+
}
|
|
266
|
+
if (task.status === "success") {
|
|
267
|
+
if ((_a = task.pollingResult) == null ? void 0 : _a.timerId) {
|
|
268
|
+
}
|
|
269
|
+
this.deleteTask({ module: module2, queueId, taskId: task.id });
|
|
270
|
+
} else {
|
|
271
|
+
let _other = {
|
|
272
|
+
status: task.status
|
|
273
|
+
};
|
|
274
|
+
if (task.status === "failure") {
|
|
275
|
+
_other.retries = task.retries + 1;
|
|
276
|
+
}
|
|
277
|
+
errorTaskIds.push(task.id);
|
|
278
|
+
this.updateTask({ module: module2, queueId, taskId: task.id, other: _other });
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
console.log("Tasks--->", "任务没有重试次数,需要删除", task);
|
|
282
|
+
this.deleteTask({ module: module2, queueId, taskId: task.id });
|
|
283
|
+
}
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.error("任务异常", error);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
taskQueueStatus = ((_b = this.getTaskQueue(payload)) == null ? void 0 : _b.some((task) => task.status === "failure")) ? "uncompleted" : "completed";
|
|
289
|
+
this.updateQueueStatus({
|
|
290
|
+
queueId,
|
|
291
|
+
module: module2,
|
|
292
|
+
status: taskQueueStatus
|
|
293
|
+
});
|
|
294
|
+
console.log("Tasks--->", "任务队列执行完成", taskQueue);
|
|
295
|
+
} else {
|
|
296
|
+
taskQueueStatus = "completed";
|
|
297
|
+
}
|
|
298
|
+
if (taskQueueStatus === "uncompleted") {
|
|
299
|
+
this.app.logger.addLog({
|
|
300
|
+
type: "info",
|
|
301
|
+
title: `任务队列执行存在失败-${queueId}`,
|
|
302
|
+
metadata: { taskQueue, errorTaskIds }
|
|
303
|
+
});
|
|
304
|
+
await this.timeout();
|
|
305
|
+
} else if (taskQueueStatus === "completed") {
|
|
306
|
+
console.log("Tasks--->", "任务队列全部执行完成");
|
|
307
|
+
callback == null ? void 0 : callback();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
deleteTask(payload) {
|
|
312
|
+
var _a, _b, _c, _d;
|
|
313
|
+
const { queueId, module: module2, taskId } = payload;
|
|
314
|
+
this.tasks[module2][queueId].tasks = (_d = (_c = (_b = (_a = this.tasks) == null ? void 0 : _a[module2]) == null ? void 0 : _b[queueId]) == null ? void 0 : _c.tasks) == null ? void 0 : _d.filter((task) => {
|
|
315
|
+
var _a2;
|
|
316
|
+
if ((_a2 = task.pollingResult) == null ? void 0 : _a2.timerId) {
|
|
317
|
+
clearTimeout(task.pollingResult.timerId);
|
|
318
|
+
}
|
|
319
|
+
return task.id !== taskId;
|
|
320
|
+
});
|
|
321
|
+
this.saveTaskQueueToLocal(this.tasks);
|
|
322
|
+
console.log("Tasks--->", "删除指定任务", queueId, module2, taskId);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @title: 重试任务
|
|
326
|
+
* @description:
|
|
327
|
+
* @return {*}
|
|
328
|
+
* @Author: zhiwei.Wang
|
|
329
|
+
* @Date: 2024-09-26 13:53
|
|
330
|
+
*/
|
|
331
|
+
retryTask(payload) {
|
|
332
|
+
const { queueId, module: module2 } = payload;
|
|
333
|
+
this.run({ queueId, module: module2 });
|
|
334
|
+
}
|
|
335
|
+
// 添加任务
|
|
336
|
+
addTask(payload) {
|
|
337
|
+
var _a, _b, _c;
|
|
338
|
+
const { queueId, module: module2, tasks } = payload;
|
|
339
|
+
const taskQueue = (_b = (_a = this.tasks[module2]) == null ? void 0 : _a[queueId]) == null ? void 0 : _b.tasks;
|
|
340
|
+
let _tasks = [...taskQueue || []];
|
|
341
|
+
let newTasks = (_c = tasks == null ? void 0 : tasks.map) == null ? void 0 : _c.call(tasks, (d) => {
|
|
342
|
+
return this.createTaskData({ ...d, queueId, module: module2 });
|
|
343
|
+
});
|
|
344
|
+
_tasks = _tasks.concat(newTasks);
|
|
345
|
+
this.setTasks({ queueId, module: module2, tasks: _tasks });
|
|
346
|
+
console.log("Tasks--->", `任务添加成功`, newTasks);
|
|
347
|
+
}
|
|
348
|
+
// 更新任务状态
|
|
349
|
+
updateTask(payload) {
|
|
350
|
+
var _a, _b, _c;
|
|
351
|
+
const { queueId, taskId, other, module: module2 } = payload;
|
|
352
|
+
let newTask = null;
|
|
353
|
+
const taskQueue = ((_b = (_a = this.tasks[module2]) == null ? void 0 : _a[queueId]) == null ? void 0 : _b.tasks) || [];
|
|
354
|
+
const updatedTasks = taskQueue.map((task) => {
|
|
355
|
+
if (task.id === taskId) {
|
|
356
|
+
newTask = { ...task, ...other };
|
|
357
|
+
return newTask;
|
|
358
|
+
}
|
|
359
|
+
return task;
|
|
360
|
+
});
|
|
361
|
+
const newState = {
|
|
362
|
+
...this.tasks,
|
|
363
|
+
[module2]: {
|
|
364
|
+
...this.tasks[module2],
|
|
365
|
+
[queueId]: {
|
|
366
|
+
...(_c = this.tasks[module2]) == null ? void 0 : _c[queueId],
|
|
367
|
+
status: updatedTasks.some((task) => task.status === "failure") ? "uncompleted" : "completed",
|
|
368
|
+
tasks: updatedTasks
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
this.saveTaskQueueToLocal(newState);
|
|
373
|
+
this.tasks = newState;
|
|
374
|
+
return newTask;
|
|
375
|
+
}
|
|
376
|
+
updateQueueStatus(payload) {
|
|
377
|
+
const { queueId, status, module: module2 } = payload;
|
|
378
|
+
const newState = {
|
|
379
|
+
...this.tasks,
|
|
380
|
+
[module2]: {
|
|
381
|
+
...this.tasks[module2],
|
|
382
|
+
[queueId]: {
|
|
383
|
+
...this.tasks[module2][queueId],
|
|
384
|
+
status
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
this.saveTaskQueueToLocal(newState);
|
|
389
|
+
this.tasks = newState;
|
|
390
|
+
}
|
|
391
|
+
// 设置任务
|
|
392
|
+
setTasks(payload) {
|
|
393
|
+
const { queueId, module: module2, tasks } = payload;
|
|
394
|
+
const moduleData = this.tasks[module2] || {};
|
|
395
|
+
const queueIdData = moduleData[queueId] || {};
|
|
396
|
+
const newState = {
|
|
397
|
+
...this.tasks,
|
|
398
|
+
[module2]: {
|
|
399
|
+
...moduleData,
|
|
400
|
+
[queueId]: {
|
|
401
|
+
...queueIdData,
|
|
402
|
+
tasks
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
this.saveTaskQueueToLocal(newState);
|
|
407
|
+
this.tasks = newState;
|
|
408
|
+
}
|
|
409
|
+
clearAllTaskTimer(tasks) {
|
|
410
|
+
var _a;
|
|
411
|
+
for (let task of tasks || []) {
|
|
412
|
+
if ((_a = task.pollingResult) == null ? void 0 : _a.timerId) {
|
|
413
|
+
clearTimeout(task.pollingResult.timerId);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
// 清空任务
|
|
418
|
+
clearTasks(payload) {
|
|
419
|
+
const { queueId, module: module2 } = payload;
|
|
420
|
+
this.clearAllTaskTimer(this.tasks[module2][queueId].tasks);
|
|
421
|
+
this.tasks[module2][queueId].tasks = [];
|
|
422
|
+
this.saveTaskQueueToLocal(this.tasks);
|
|
423
|
+
console.log("Tasks--->", "清空指定任务", queueId, module2);
|
|
424
|
+
}
|
|
425
|
+
// 清空全部任务
|
|
426
|
+
clearAllTasks() {
|
|
427
|
+
this.tasks = {};
|
|
428
|
+
this.saveTaskQueueToLocal(this.tasks);
|
|
429
|
+
console.log("Tasks--->", "清空全部任务");
|
|
430
|
+
}
|
|
431
|
+
watchTask(callback) {
|
|
432
|
+
this.watchTaskCallback = callback;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
436
|
+
0 && (module.exports = {
|
|
437
|
+
TasksManager
|
|
438
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
|
|
2
|
+
export interface Task {
|
|
3
|
+
id?: string;
|
|
4
|
+
type?: "local" | "cloud";
|
|
5
|
+
retries?: number;
|
|
6
|
+
maxRetries?: number;
|
|
7
|
+
status?: TaskRunStatus;
|
|
8
|
+
action: string;
|
|
9
|
+
payload: any;
|
|
10
|
+
beforeAction?: string;
|
|
11
|
+
beforePayload?: any;
|
|
12
|
+
afterAction?: string;
|
|
13
|
+
afterPayload?: any;
|
|
14
|
+
polling?: {
|
|
15
|
+
interval?: number;
|
|
16
|
+
};
|
|
17
|
+
pollingResult?: {
|
|
18
|
+
count: number;
|
|
19
|
+
timerId?: any;
|
|
20
|
+
};
|
|
21
|
+
manual?: boolean;
|
|
22
|
+
destroy?: boolean;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
export interface TaskConfig {
|
|
26
|
+
tasks: Task[];
|
|
27
|
+
}
|
|
28
|
+
declare type TaskModuleName = string;
|
|
29
|
+
declare type TaskQueueName = string;
|
|
30
|
+
declare type TaskStatus = "uncompleted" | "completed";
|
|
31
|
+
export interface TaskQueue {
|
|
32
|
+
status: TaskStatus;
|
|
33
|
+
tasks: Task[];
|
|
34
|
+
}
|
|
35
|
+
export interface RunTaskParams {
|
|
36
|
+
module: TaskModuleName;
|
|
37
|
+
queueId: TaskQueueName;
|
|
38
|
+
callback?: () => void;
|
|
39
|
+
}
|
|
40
|
+
export interface DeleteTaskParams {
|
|
41
|
+
module: TaskModuleName;
|
|
42
|
+
queueId: TaskQueueName;
|
|
43
|
+
taskId: string;
|
|
44
|
+
}
|
|
45
|
+
export interface AddTaskParams {
|
|
46
|
+
module: TaskModuleName;
|
|
47
|
+
queueId: TaskQueueName;
|
|
48
|
+
tasks: Task[];
|
|
49
|
+
}
|
|
50
|
+
export interface TaskRunResult {
|
|
51
|
+
status: TaskRunStatus;
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
}
|
|
54
|
+
export interface TasksModule {
|
|
55
|
+
[key: TaskModuleName]: {
|
|
56
|
+
[key: TaskQueueName]: {
|
|
57
|
+
status: TaskStatus;
|
|
58
|
+
tasks: Task[];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -12,6 +12,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
};
|
|
13
13
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
14
|
|
|
15
|
-
// src/
|
|
15
|
+
// src/tasks/type.ts
|
|
16
16
|
var type_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(type_exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/tasks/useTasks.tsx
|
|
20
|
+
var useTasks_exports = {};
|
|
21
|
+
__export(useTasks_exports, {
|
|
22
|
+
default: () => useTasks_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useTasks_exports);
|
|
25
|
+
var import_app = require("../app");
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var useTasks = () => {
|
|
28
|
+
const { app } = (0, import_app.useApp)();
|
|
29
|
+
const [tasks, setTasks] = (0, import_react.useState)({});
|
|
30
|
+
(0, import_react.useEffect)(() => {
|
|
31
|
+
app.tasksManager.watchTask((taskModule) => {
|
|
32
|
+
setTasks(taskModule);
|
|
33
|
+
});
|
|
34
|
+
}, []);
|
|
35
|
+
return { tasks };
|
|
36
|
+
};
|
|
37
|
+
var useTasks_default = useTasks;
|
package/lib/type.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface CoreConfig {
|
|
2
2
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/variables/VariablesProvider.tsx
|
|
30
|
+
var VariablesProvider_exports = {};
|
|
31
|
+
__export(VariablesProvider_exports, {
|
|
32
|
+
VariablesProvider: () => VariablesProvider,
|
|
33
|
+
useVariablesContext: () => useVariablesContext
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(VariablesProvider_exports);
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var VariablesContext = (0, import_react.createContext)({});
|
|
38
|
+
VariablesContext.displayName = "VariablesContext";
|
|
39
|
+
var useVariablesContext = () => {
|
|
40
|
+
return import_react.default.useContext(VariablesContext);
|
|
41
|
+
};
|
|
42
|
+
var VariablesProvider = ({
|
|
43
|
+
children
|
|
44
|
+
}) => {
|
|
45
|
+
return /* @__PURE__ */ import_react.default.createElement(VariablesProvider.Provider, { value: {} }, children);
|
|
46
|
+
};
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
VariablesProvider,
|
|
50
|
+
useVariablesContext
|
|
51
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/variables/config.ts
|
|
20
|
+
var config_exports = {};
|
|
21
|
+
__export(config_exports, {
|
|
22
|
+
getConfig: () => getConfig,
|
|
23
|
+
setConfig: () => setConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(config_exports);
|
|
26
|
+
var defaultConfig = {
|
|
27
|
+
globalVariableMap: {}
|
|
28
|
+
};
|
|
29
|
+
var config = { ...defaultConfig };
|
|
30
|
+
var setConfig = (newConfig) => {
|
|
31
|
+
config = { ...config, ...newConfig };
|
|
32
|
+
};
|
|
33
|
+
var getConfig = () => config;
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
getConfig,
|
|
37
|
+
setConfig
|
|
38
|
+
});
|