@pisell/core 0.0.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/README.md +1 -0
- package/es/app/app.d.ts +101 -0
- package/es/app/app.js +177 -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 +52 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/application.js +469 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/applicationManager/index.js +206 -0
- package/es/aws/index.d.ts +16 -0
- package/es/aws/index.js +76 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/const.js +13 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/index.js +91 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/cmd/type.js +1 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/config.d.ts +3 -0
- package/es/config.js +14 -0
- 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 +8 -0
- package/es/data/index.js +16 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +26 -0
- package/es/history/index.js +80 -0
- package/es/history/type.d.ts +2 -0
- package/es/history/type.js +1 -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 +8 -0
- package/es/index.js +10 -0
- package/es/indexDB/index.d.ts +296 -0
- package/es/indexDB/index.js +1619 -0
- package/es/locales/en.d.ts +3 -0
- package/es/locales/en.js +5 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/index.js +199 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/type.js +1 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-CN.js +5 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/locales/zh-HK.js +5 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +135 -0
- package/es/logger/index.js +870 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +165 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -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 +73 -0
- package/es/pubsub/index.js +166 -0
- package/es/render/index.d.ts +0 -0
- package/es/render/index.js +0 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +372 -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 +63 -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 +267 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +57 -0
- package/es/request/type.js +10 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -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 +151 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -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 +184 -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 +448 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/socket.js +613 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/index.js +1119 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +2 -0
- package/es/type.js +1 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- 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 +101 -0
- package/lib/app/app.js +171 -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 +197 -0
- package/lib/applicationManager/application.js +280 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/applicationManager/index.js +88 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/aws/index.js +67 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/const.js +39 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/index.js +96 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/cmd/type.js +17 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +36 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +62 -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 +8 -0
- package/lib/data/index.js +38 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +26 -0
- package/lib/history/index.js +99 -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 +8 -0
- package/lib/index.js +58 -0
- package/lib/indexDB/index.d.ts +296 -0
- package/lib/indexDB/index.js +767 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +29 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/index.js +159 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/type.js +17 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-CN.js +29 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/locales/zh-HK.js +29 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/logger/index.js +476 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +125 -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 +69 -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 +73 -0
- package/lib/pubsub/index.js +141 -0
- package/lib/render/index.d.ts +0 -0
- package/lib/render/index.js +0 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +195 -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 +69 -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 +210 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +57 -0
- package/lib/request/type.js +36 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -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 +121 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +340 -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 +157 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +198 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +350 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +157 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/socket.js +426 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +64 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/index.js +710 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/tasks/type.js +17 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +2 -0
- package/lib/type.js +17 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- 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 +49 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 定时任务示例代码
|
|
3
|
+
* 本文件展示了如何使用定时任务功能
|
|
4
|
+
*
|
|
5
|
+
* 重要提示:
|
|
6
|
+
* - 定时任务必须添加到 'scheduledTasks' 模块才能生效
|
|
7
|
+
* - 在其他模块中,scheduled 配置会被忽略,任务将作为普通任务立即执行
|
|
8
|
+
* - 这是为了性能优化,避免在所有模块中检查定时任务配置
|
|
9
|
+
*/
|
|
10
|
+
import { TasksManager } from './index';
|
|
11
|
+
/**
|
|
12
|
+
* 示例1:创建一次性定时任务
|
|
13
|
+
* 在特定时间点执行一次
|
|
14
|
+
*
|
|
15
|
+
* 注意:定时任务必须添加到 'scheduledTasks' 模块才能生效
|
|
16
|
+
*/
|
|
17
|
+
export declare function createOnceScheduledTask(tasksManager: TasksManager): void;
|
|
18
|
+
/**
|
|
19
|
+
* 示例2:创建每日重复的定时任务
|
|
20
|
+
* 每天在固定时间执行
|
|
21
|
+
*/
|
|
22
|
+
export declare function createDailyScheduledTask(tasksManager: TasksManager): void;
|
|
23
|
+
/**
|
|
24
|
+
* 示例3:创建带结束时间的重复任务
|
|
25
|
+
* 在特定时间段内重复执行
|
|
26
|
+
*/
|
|
27
|
+
export declare function createLimitedRepeatTask(tasksManager: TasksManager): void;
|
|
28
|
+
/**
|
|
29
|
+
* 示例4:创建多个时间点的任务
|
|
30
|
+
* 在一天中的多个时间点分别执行
|
|
31
|
+
*/
|
|
32
|
+
export declare function createMultiTimeTask(tasksManager: TasksManager): void;
|
|
33
|
+
/**
|
|
34
|
+
* 示例5:创建每周重复任务
|
|
35
|
+
* 每周一早上9点执行周报
|
|
36
|
+
*/
|
|
37
|
+
export declare function createWeeklyTask(tasksManager: TasksManager): void;
|
|
38
|
+
/**
|
|
39
|
+
* 示例6:创建每月重复任务
|
|
40
|
+
* 每月1号生成月报
|
|
41
|
+
*/
|
|
42
|
+
export declare function createMonthlyTask(tasksManager: TasksManager): void;
|
|
43
|
+
/**
|
|
44
|
+
* 示例7:查询和管理定时任务
|
|
45
|
+
*/
|
|
46
|
+
export declare function manageScheduledTasks(tasksManager: TasksManager): void;
|
|
47
|
+
/**
|
|
48
|
+
* 完整使用示例
|
|
49
|
+
*/
|
|
50
|
+
export declare function fullExample(app: any): void;
|
|
51
|
+
declare const _default: {
|
|
52
|
+
createOnceScheduledTask: typeof createOnceScheduledTask;
|
|
53
|
+
createDailyScheduledTask: typeof createDailyScheduledTask;
|
|
54
|
+
createLimitedRepeatTask: typeof createLimitedRepeatTask;
|
|
55
|
+
createMultiTimeTask: typeof createMultiTimeTask;
|
|
56
|
+
createWeeklyTask: typeof createWeeklyTask;
|
|
57
|
+
createMonthlyTask: typeof createMonthlyTask;
|
|
58
|
+
manageScheduledTasks: typeof manageScheduledTasks;
|
|
59
|
+
fullExample: typeof fullExample;
|
|
60
|
+
};
|
|
61
|
+
export default _default;
|
|
@@ -0,0 +1,267 @@
|
|
|
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/scheduledTasksExample.ts
|
|
30
|
+
var scheduledTasksExample_exports = {};
|
|
31
|
+
__export(scheduledTasksExample_exports, {
|
|
32
|
+
createDailyScheduledTask: () => createDailyScheduledTask,
|
|
33
|
+
createLimitedRepeatTask: () => createLimitedRepeatTask,
|
|
34
|
+
createMonthlyTask: () => createMonthlyTask,
|
|
35
|
+
createMultiTimeTask: () => createMultiTimeTask,
|
|
36
|
+
createOnceScheduledTask: () => createOnceScheduledTask,
|
|
37
|
+
createWeeklyTask: () => createWeeklyTask,
|
|
38
|
+
default: () => scheduledTasksExample_default,
|
|
39
|
+
fullExample: () => fullExample,
|
|
40
|
+
manageScheduledTasks: () => manageScheduledTasks
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(scheduledTasksExample_exports);
|
|
43
|
+
var import_index = require("./index");
|
|
44
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
45
|
+
function createOnceScheduledTask(tasksManager) {
|
|
46
|
+
const executeTime = (0, import_dayjs.default)().add(5, "minute").format("YYYY-MM-DD HH:mm:ss");
|
|
47
|
+
tasksManager.addTask({
|
|
48
|
+
module: "scheduledTasks",
|
|
49
|
+
// 定时任务必须使用 scheduledTasks 模块
|
|
50
|
+
queueId: "reminder",
|
|
51
|
+
tasks: [{
|
|
52
|
+
action: "sendNotification",
|
|
53
|
+
payload: {
|
|
54
|
+
message: "这是一个定时提醒",
|
|
55
|
+
priority: "high"
|
|
56
|
+
},
|
|
57
|
+
scheduled: {
|
|
58
|
+
executeAt: executeTime
|
|
59
|
+
},
|
|
60
|
+
maxRetries: 3
|
|
61
|
+
}]
|
|
62
|
+
});
|
|
63
|
+
console.log(`定时任务已创建,将在 ${executeTime} 执行`);
|
|
64
|
+
tasksManager.run({
|
|
65
|
+
module: "scheduledTasks",
|
|
66
|
+
queueId: "reminder",
|
|
67
|
+
callback: () => {
|
|
68
|
+
console.log("定时任务执行完成");
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function createDailyScheduledTask(tasksManager) {
|
|
73
|
+
const startTime = (0, import_dayjs.default)().add(1, "day").hour(9).minute(0).second(0).format("YYYY-MM-DD HH:mm:ss");
|
|
74
|
+
tasksManager.addTask({
|
|
75
|
+
module: "scheduledTasks",
|
|
76
|
+
queueId: "daily-report",
|
|
77
|
+
tasks: [{
|
|
78
|
+
action: "generateDailyReport",
|
|
79
|
+
payload: {
|
|
80
|
+
type: "sales",
|
|
81
|
+
recipients: ["manager@company.com"]
|
|
82
|
+
},
|
|
83
|
+
scheduled: {
|
|
84
|
+
executeAt: startTime,
|
|
85
|
+
repeat: true,
|
|
86
|
+
repeatType: "daily",
|
|
87
|
+
repeatInterval: 1
|
|
88
|
+
},
|
|
89
|
+
maxRetries: 3,
|
|
90
|
+
destroy: false
|
|
91
|
+
// 持久化任务,不会在应用卸载时清除
|
|
92
|
+
}]
|
|
93
|
+
});
|
|
94
|
+
console.log(`每日定时任务已创建,首次执行时间: ${startTime}`);
|
|
95
|
+
tasksManager.run({
|
|
96
|
+
module: "scheduledTasks",
|
|
97
|
+
queueId: "daily-report"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function createLimitedRepeatTask(tasksManager) {
|
|
101
|
+
const startTime = (0, import_dayjs.default)().add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
|
|
102
|
+
const endTime = (0, import_dayjs.default)().add(7, "day").format("YYYY-MM-DD HH:mm:ss");
|
|
103
|
+
tasksManager.addTask({
|
|
104
|
+
module: "scheduledTasks",
|
|
105
|
+
queueId: "campaign",
|
|
106
|
+
tasks: [{
|
|
107
|
+
action: "sendPromotionMessage",
|
|
108
|
+
payload: {
|
|
109
|
+
campaign: "双十一预热",
|
|
110
|
+
discount: "8折优惠"
|
|
111
|
+
},
|
|
112
|
+
scheduled: {
|
|
113
|
+
executeAt: startTime,
|
|
114
|
+
repeat: true,
|
|
115
|
+
repeatType: "daily",
|
|
116
|
+
repeatInterval: 1,
|
|
117
|
+
endAt: endTime
|
|
118
|
+
// 7天后结束
|
|
119
|
+
},
|
|
120
|
+
maxRetries: 2
|
|
121
|
+
}]
|
|
122
|
+
});
|
|
123
|
+
console.log(`限时促销任务已创建`);
|
|
124
|
+
console.log(`执行时间: ${startTime} 至 ${endTime}`);
|
|
125
|
+
tasksManager.run({
|
|
126
|
+
module: "scheduledTasks",
|
|
127
|
+
queueId: "campaign"
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function createMultiTimeTask(tasksManager) {
|
|
131
|
+
const today = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
132
|
+
tasksManager.addTask({
|
|
133
|
+
module: "scheduledTasks",
|
|
134
|
+
queueId: "medication",
|
|
135
|
+
tasks: [{
|
|
136
|
+
action: "sendMedicationReminder",
|
|
137
|
+
payload: {
|
|
138
|
+
medicine: "阿莫西林",
|
|
139
|
+
dosage: "1片"
|
|
140
|
+
},
|
|
141
|
+
scheduled: {
|
|
142
|
+
executeAt: [
|
|
143
|
+
`${today} 08:00:00`,
|
|
144
|
+
// 早上8点
|
|
145
|
+
`${today} 12:00:00`,
|
|
146
|
+
// 中午12点
|
|
147
|
+
`${today} 18:00:00`
|
|
148
|
+
// 下午6点
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
maxRetries: 3
|
|
152
|
+
}]
|
|
153
|
+
});
|
|
154
|
+
console.log(`多时间点任务已创建,今天将在 8:00, 12:00, 18:00 执行`);
|
|
155
|
+
tasksManager.run({
|
|
156
|
+
module: "scheduledTasks",
|
|
157
|
+
queueId: "medication"
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function createWeeklyTask(tasksManager) {
|
|
161
|
+
let nextMonday = (0, import_dayjs.default)();
|
|
162
|
+
while (nextMonday.day() !== 1) {
|
|
163
|
+
nextMonday = nextMonday.add(1, "day");
|
|
164
|
+
}
|
|
165
|
+
const startTime = nextMonday.hour(9).minute(0).second(0).format("YYYY-MM-DD HH:mm:ss");
|
|
166
|
+
tasksManager.addTask({
|
|
167
|
+
module: "scheduledTasks",
|
|
168
|
+
queueId: "weekly-report",
|
|
169
|
+
tasks: [{
|
|
170
|
+
action: "generateWeeklyReport",
|
|
171
|
+
payload: {
|
|
172
|
+
type: "team-summary",
|
|
173
|
+
recipients: ["team@company.com"]
|
|
174
|
+
},
|
|
175
|
+
scheduled: {
|
|
176
|
+
executeAt: startTime,
|
|
177
|
+
repeat: true,
|
|
178
|
+
repeatType: "weekly",
|
|
179
|
+
repeatInterval: 1
|
|
180
|
+
// 每周执行一次
|
|
181
|
+
},
|
|
182
|
+
maxRetries: 3,
|
|
183
|
+
destroy: false
|
|
184
|
+
}]
|
|
185
|
+
});
|
|
186
|
+
console.log(`周报任务已创建,下次执行时间: ${startTime}`);
|
|
187
|
+
tasksManager.run({
|
|
188
|
+
module: "scheduledTasks",
|
|
189
|
+
queueId: "weekly-report"
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function createMonthlyTask(tasksManager) {
|
|
193
|
+
const nextMonth = (0, import_dayjs.default)().add(1, "month").date(1).hour(9).minute(0).second(0);
|
|
194
|
+
const startTime = nextMonth.format("YYYY-MM-DD HH:mm:ss");
|
|
195
|
+
tasksManager.addTask({
|
|
196
|
+
module: "scheduledTasks",
|
|
197
|
+
queueId: "monthly-billing",
|
|
198
|
+
tasks: [{
|
|
199
|
+
action: "generateMonthlyInvoice",
|
|
200
|
+
payload: {
|
|
201
|
+
type: "subscription",
|
|
202
|
+
autoSend: true
|
|
203
|
+
},
|
|
204
|
+
scheduled: {
|
|
205
|
+
executeAt: startTime,
|
|
206
|
+
repeat: true,
|
|
207
|
+
repeatType: "monthly",
|
|
208
|
+
repeatInterval: 1
|
|
209
|
+
// 每月执行一次
|
|
210
|
+
},
|
|
211
|
+
maxRetries: 3,
|
|
212
|
+
destroy: false
|
|
213
|
+
}]
|
|
214
|
+
});
|
|
215
|
+
console.log(`月度账单任务已创建,下次执行时间: ${startTime}`);
|
|
216
|
+
tasksManager.run({
|
|
217
|
+
module: "scheduledTasks",
|
|
218
|
+
queueId: "monthly-billing"
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function manageScheduledTasks(tasksManager) {
|
|
222
|
+
const allTasks = tasksManager.getTasks();
|
|
223
|
+
console.log("当前所有任务:", allTasks);
|
|
224
|
+
}
|
|
225
|
+
function fullExample(app) {
|
|
226
|
+
const tasksManager = import_index.TasksManager.getInstance(app);
|
|
227
|
+
tasksManager.addTaskFunction("sendNotification", async ({ task }) => {
|
|
228
|
+
const { message, priority } = task.payload;
|
|
229
|
+
console.log(`[${priority}] 发送通知: ${message}`);
|
|
230
|
+
return { status: "success" };
|
|
231
|
+
});
|
|
232
|
+
tasksManager.addTaskFunction("generateDailyReport", async ({ task }) => {
|
|
233
|
+
const { type, recipients } = task.payload;
|
|
234
|
+
console.log(`生成 ${type} 日报,发送给:`, recipients);
|
|
235
|
+
return { status: "success" };
|
|
236
|
+
});
|
|
237
|
+
tasksManager.addTaskFunction("sendPromotionMessage", async ({ task }) => {
|
|
238
|
+
const { campaign, discount } = task.payload;
|
|
239
|
+
console.log(`发送促销消息: ${campaign} - ${discount}`);
|
|
240
|
+
return { status: "success" };
|
|
241
|
+
});
|
|
242
|
+
createOnceScheduledTask(tasksManager);
|
|
243
|
+
tasksManager.watchTask((taskModule) => {
|
|
244
|
+
console.log("任务状态更新:", taskModule);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
var scheduledTasksExample_default = {
|
|
248
|
+
createOnceScheduledTask,
|
|
249
|
+
createDailyScheduledTask,
|
|
250
|
+
createLimitedRepeatTask,
|
|
251
|
+
createMultiTimeTask,
|
|
252
|
+
createWeeklyTask,
|
|
253
|
+
createMonthlyTask,
|
|
254
|
+
manageScheduledTasks,
|
|
255
|
+
fullExample
|
|
256
|
+
};
|
|
257
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
258
|
+
0 && (module.exports = {
|
|
259
|
+
createDailyScheduledTask,
|
|
260
|
+
createLimitedRepeatTask,
|
|
261
|
+
createMonthlyTask,
|
|
262
|
+
createMultiTimeTask,
|
|
263
|
+
createOnceScheduledTask,
|
|
264
|
+
createWeeklyTask,
|
|
265
|
+
fullExample,
|
|
266
|
+
manageScheduledTasks
|
|
267
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
scheduled?: {
|
|
22
|
+
executeAt: string | string[];
|
|
23
|
+
repeat?: boolean;
|
|
24
|
+
repeatType?: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
25
|
+
repeatInterval?: number;
|
|
26
|
+
endAt?: string;
|
|
27
|
+
};
|
|
28
|
+
scheduledResult?: {
|
|
29
|
+
count: number;
|
|
30
|
+
timerId?: any;
|
|
31
|
+
nextExecuteTime?: string;
|
|
32
|
+
};
|
|
33
|
+
manual?: boolean;
|
|
34
|
+
destroy?: boolean;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
export interface TaskConfig {
|
|
38
|
+
tasks: Task[];
|
|
39
|
+
}
|
|
40
|
+
declare type TaskModuleName = string;
|
|
41
|
+
declare type TaskQueueName = string;
|
|
42
|
+
declare type TaskStatus = "uncompleted" | "completed";
|
|
43
|
+
export interface TaskQueue {
|
|
44
|
+
status: TaskStatus;
|
|
45
|
+
tasks: Task[];
|
|
46
|
+
isRunning?: boolean;
|
|
47
|
+
progress?: {
|
|
48
|
+
total: number;
|
|
49
|
+
completed: number;
|
|
50
|
+
failed: number;
|
|
51
|
+
inProgress: number;
|
|
52
|
+
};
|
|
53
|
+
lastRunAt?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface RunTaskParams {
|
|
56
|
+
module: TaskModuleName;
|
|
57
|
+
queueId: TaskQueueName;
|
|
58
|
+
callback?: () => void;
|
|
59
|
+
}
|
|
60
|
+
export interface DeleteTaskParams {
|
|
61
|
+
module: TaskModuleName;
|
|
62
|
+
queueId: TaskQueueName;
|
|
63
|
+
taskId: string;
|
|
64
|
+
}
|
|
65
|
+
export interface AddTaskParams {
|
|
66
|
+
module: TaskModuleName;
|
|
67
|
+
queueId: TaskQueueName;
|
|
68
|
+
tasks: Task[];
|
|
69
|
+
}
|
|
70
|
+
export interface AddTaskDataParams {
|
|
71
|
+
module: TaskModuleName;
|
|
72
|
+
queueId: TaskQueueName;
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
}
|
|
75
|
+
export interface TaskRunResult {
|
|
76
|
+
status: TaskRunStatus;
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 任务模块
|
|
81
|
+
* 注意:'scheduledTasks' 是保留的模块名,专门用于定时任务
|
|
82
|
+
* 在其他模块中,scheduled 配置会被忽略,任务将作为普通任务执行
|
|
83
|
+
*/
|
|
84
|
+
export interface TasksModule {
|
|
85
|
+
[key: TaskModuleName]: {
|
|
86
|
+
[key: TaskQueueName]: {
|
|
87
|
+
status: TaskStatus;
|
|
88
|
+
tasks: Task[];
|
|
89
|
+
isRunning?: boolean;
|
|
90
|
+
progress?: {
|
|
91
|
+
total: number;
|
|
92
|
+
completed: number;
|
|
93
|
+
failed: number;
|
|
94
|
+
inProgress: number;
|
|
95
|
+
};
|
|
96
|
+
lastRunAt?: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/tasks/type.ts
|
|
16
|
+
var type_exports = {};
|
|
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
ADDED
package/lib/type.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/type.ts
|
|
16
|
+
var type_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(type_exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare type ThrottleLevel = number;
|
|
2
|
+
export interface ThrottleExecuteContext {
|
|
3
|
+
/** 事务唯一 key */
|
|
4
|
+
key: string;
|
|
5
|
+
/** 当前节流窗口内的触发次数 */
|
|
6
|
+
count: number;
|
|
7
|
+
/** 是否首次立即执行 */
|
|
8
|
+
isFirst: boolean;
|
|
9
|
+
/** 当前节流等级 */
|
|
10
|
+
level: ThrottleLevel;
|
|
11
|
+
/** 上一次执行时间 */
|
|
12
|
+
lastExecuteTime: number;
|
|
13
|
+
}
|
|
14
|
+
export declare type ThrottleHandler = (ctx: ThrottleExecuteContext) => void | Promise<void>;
|
|
15
|
+
export declare const DEFAULT_THROTTLE_INTERVALS: number[];
|
|
16
|
+
export declare class AdaptiveThrottle {
|
|
17
|
+
private store;
|
|
18
|
+
private intervals;
|
|
19
|
+
constructor(intervals?: number[]);
|
|
20
|
+
/**
|
|
21
|
+
* 触发事务
|
|
22
|
+
*/
|
|
23
|
+
trigger(key: string, handler: ThrottleHandler): void;
|
|
24
|
+
/**
|
|
25
|
+
* 调度下一次节流执行
|
|
26
|
+
*/
|
|
27
|
+
private schedule;
|
|
28
|
+
/**
|
|
29
|
+
* 主动清理某个事务
|
|
30
|
+
*/
|
|
31
|
+
clear(key: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* 清空所有事务
|
|
34
|
+
*/
|
|
35
|
+
clearAll(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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/utils/adaptiveThrottle/index.ts
|
|
20
|
+
var adaptiveThrottle_exports = {};
|
|
21
|
+
__export(adaptiveThrottle_exports, {
|
|
22
|
+
AdaptiveThrottle: () => AdaptiveThrottle,
|
|
23
|
+
DEFAULT_THROTTLE_INTERVALS: () => DEFAULT_THROTTLE_INTERVALS
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(adaptiveThrottle_exports);
|
|
26
|
+
var DEFAULT_THROTTLE_INTERVALS = [
|
|
27
|
+
5 * 60 * 1e3,
|
|
28
|
+
// 5分钟
|
|
29
|
+
30 * 60 * 1e3,
|
|
30
|
+
// 30分钟
|
|
31
|
+
60 * 60 * 1e3,
|
|
32
|
+
// 1小时
|
|
33
|
+
6 * 60 * 60 * 1e3,
|
|
34
|
+
// 6小时
|
|
35
|
+
24 * 60 * 60 * 1e3
|
|
36
|
+
// 1天
|
|
37
|
+
];
|
|
38
|
+
var AdaptiveThrottle = class {
|
|
39
|
+
store = /* @__PURE__ */ new Map();
|
|
40
|
+
intervals;
|
|
41
|
+
constructor(intervals = DEFAULT_THROTTLE_INTERVALS) {
|
|
42
|
+
this.intervals = intervals;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 触发事务
|
|
46
|
+
*/
|
|
47
|
+
trigger(key, handler) {
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
let record = this.store.get(key);
|
|
50
|
+
if (!record) {
|
|
51
|
+
handler({
|
|
52
|
+
key,
|
|
53
|
+
count: 1,
|
|
54
|
+
isFirst: true,
|
|
55
|
+
level: 0,
|
|
56
|
+
lastExecuteTime: now
|
|
57
|
+
});
|
|
58
|
+
record = {
|
|
59
|
+
key,
|
|
60
|
+
count: 0,
|
|
61
|
+
level: 0,
|
|
62
|
+
lastExecuteTime: now
|
|
63
|
+
};
|
|
64
|
+
this.store.set(key, record);
|
|
65
|
+
this.schedule(key, handler, record);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
record.count++;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 调度下一次节流执行
|
|
72
|
+
*/
|
|
73
|
+
schedule(key, handler, record) {
|
|
74
|
+
const interval = this.intervals[record.level];
|
|
75
|
+
record.timer = setTimeout(async () => {
|
|
76
|
+
const count = record.count;
|
|
77
|
+
if (count > 0) {
|
|
78
|
+
await handler({
|
|
79
|
+
key,
|
|
80
|
+
count,
|
|
81
|
+
isFirst: false,
|
|
82
|
+
level: record.level,
|
|
83
|
+
lastExecuteTime: record.lastExecuteTime
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (count > 0 && record.level < this.intervals.length - 1) {
|
|
87
|
+
record.level++;
|
|
88
|
+
}
|
|
89
|
+
record.count = 0;
|
|
90
|
+
record.lastExecuteTime = Date.now();
|
|
91
|
+
this.schedule(key, handler, record);
|
|
92
|
+
}, interval);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 主动清理某个事务
|
|
96
|
+
*/
|
|
97
|
+
clear(key) {
|
|
98
|
+
const record = this.store.get(key);
|
|
99
|
+
if (!record) return;
|
|
100
|
+
if (record.timer) {
|
|
101
|
+
clearTimeout(record.timer);
|
|
102
|
+
}
|
|
103
|
+
this.store.delete(key);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 清空所有事务
|
|
107
|
+
*/
|
|
108
|
+
clearAll() {
|
|
109
|
+
this.store.forEach((record) => {
|
|
110
|
+
if (record.timer) {
|
|
111
|
+
clearTimeout(record.timer);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
this.store.clear();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
AdaptiveThrottle,
|
|
120
|
+
DEFAULT_THROTTLE_INTERVALS
|
|
121
|
+
});
|