@nocobase/plugin-async-task-manager 1.6.0-alpha.8 → 1.6.0-alpha.9

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.
@@ -8,12 +8,13 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.6.0-alpha.8",
11
+ "@nocobase/client": "1.6.0-alpha.9",
12
12
  "react": "18.2.0",
13
13
  "antd": "5.12.8",
14
- "@nocobase/logger": "1.6.0-alpha.8",
15
- "@nocobase/server": "1.6.0-alpha.8",
16
- "@nocobase/plugin-error-handler": "1.6.0-alpha.8",
14
+ "@nocobase/logger": "1.6.0-alpha.9",
15
+ "@nocobase/server": "1.6.0-alpha.9",
16
+ "lodash": "4.17.21",
17
+ "@nocobase/plugin-error-handler": "1.6.0-alpha.9",
17
18
  "@ant-design/icons": "5.2.6",
18
19
  "dayjs": "1.11.10"
19
20
  };
@@ -1 +1 @@
1
- {"name":"uuid","version":"3.4.0","description":"RFC4122 (v1, v4, and v5) UUIDs","commitlint":{"extends":["@commitlint/config-conventional"]},"keywords":["uuid","guid","rfc4122"],"license":"MIT","bin":{"uuid":"./bin/uuid"},"devDependencies":{"@commitlint/cli":"~8.2.0","@commitlint/config-conventional":"~8.2.0","eslint":"~6.4.0","husky":"~3.0.5","mocha":"6.2.0","runmd":"1.2.1","standard-version":"7.0.0"},"scripts":{"lint":"eslint .","test":"npm run lint && mocha test/test.js","md":"runmd --watch --output=README.md README_js.md","release":"standard-version","prepare":"runmd --output=README.md README_js.md"},"browser":{"./lib/rng.js":"./lib/rng-browser.js","./lib/sha1.js":"./lib/sha1-browser.js","./lib/md5.js":"./lib/md5-browser.js"},"repository":{"type":"git","url":"https://github.com/uuidjs/uuid.git"},"husky":{"hooks":{"commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"_lastModified":"2025-01-02T11:38:54.439Z"}
1
+ {"name":"uuid","version":"3.4.0","description":"RFC4122 (v1, v4, and v5) UUIDs","commitlint":{"extends":["@commitlint/config-conventional"]},"keywords":["uuid","guid","rfc4122"],"license":"MIT","bin":{"uuid":"./bin/uuid"},"devDependencies":{"@commitlint/cli":"~8.2.0","@commitlint/config-conventional":"~8.2.0","eslint":"~6.4.0","husky":"~3.0.5","mocha":"6.2.0","runmd":"1.2.1","standard-version":"7.0.0"},"scripts":{"lint":"eslint .","test":"npm run lint && mocha test/test.js","md":"runmd --watch --output=README.md README_js.md","release":"standard-version","prepare":"runmd --output=README.md README_js.md"},"browser":{"./lib/rng.js":"./lib/rng-browser.js","./lib/sha1.js":"./lib/sha1-browser.js","./lib/md5.js":"./lib/md5-browser.js"},"repository":{"type":"git","url":"https://github.com/uuidjs/uuid.git"},"husky":{"hooks":{"commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"_lastModified":"2025-01-06T05:51:59.635Z"}
@@ -1,7 +1,9 @@
1
1
  import { Plugin } from '@nocobase/server';
2
2
  export declare class PluginAsyncExportServer extends Plugin {
3
+ private progressThrottles;
3
4
  afterAdd(): Promise<void>;
4
5
  beforeLoad(): Promise<void>;
6
+ getThrottledProgressEmitter(taskId: string, userId: string): Function;
5
7
  load(): Promise<void>;
6
8
  }
7
9
  export default PluginAsyncExportServer;
@@ -44,7 +44,9 @@ var import_server = require("@nocobase/server");
44
44
  var import_base_task_manager = require("./base-task-manager");
45
45
  var import_command_task_type = require("./command-task-type");
46
46
  var import_async_tasks = __toESM(require("./resourcers/async-tasks"));
47
+ var import_lodash = require("lodash");
47
48
  class PluginAsyncExportServer extends import_server.Plugin {
49
+ progressThrottles = /* @__PURE__ */ new Map();
48
50
  async afterAdd() {
49
51
  }
50
52
  async beforeLoad() {
@@ -57,6 +59,31 @@ class PluginAsyncExportServer extends import_server.Plugin {
57
59
  this.app.container.get("AsyncTaskManager").registerTaskType(import_command_task_type.CommandTaskType);
58
60
  this.app.acl.allow("asyncTasks", ["get", "fetchFile"], "loggedIn");
59
61
  }
62
+ getThrottledProgressEmitter(taskId, userId) {
63
+ if (!this.progressThrottles.has(taskId)) {
64
+ this.progressThrottles.set(
65
+ taskId,
66
+ (0, import_lodash.throttle)(
67
+ (progress) => {
68
+ this.app.emit("ws:sendToTag", {
69
+ tagKey: "userId",
70
+ tagValue: userId,
71
+ message: {
72
+ type: "async-tasks:progress",
73
+ payload: {
74
+ taskId,
75
+ progress
76
+ }
77
+ }
78
+ });
79
+ },
80
+ 500,
81
+ { leading: true, trailing: true }
82
+ )
83
+ );
84
+ }
85
+ return this.progressThrottles.get(taskId);
86
+ }
60
87
  async load() {
61
88
  this.app.resourceManager.define(import_async_tasks.default);
62
89
  const asyncTaskManager = this.app.container.get("AsyncTaskManager");
@@ -97,36 +124,31 @@ class PluginAsyncExportServer extends import_server.Plugin {
97
124
  asyncTaskManager.on("taskProgress", ({ task, progress }) => {
98
125
  const userId = task.tags["userId"];
99
126
  if (userId) {
100
- this.app.emit("ws:sendToTag", {
101
- tagKey: "userId",
102
- tagValue: userId,
103
- message: {
104
- type: "async-tasks:progress",
105
- payload: {
106
- taskId: task.taskId,
107
- progress
108
- }
109
- }
110
- });
127
+ const throttledEmit = this.getThrottledProgressEmitter(task.taskId, userId);
128
+ throttledEmit(progress);
111
129
  }
112
130
  });
113
131
  asyncTaskManager.on("taskStatusChange", ({ task, status }) => {
114
132
  const userId = task.tags["userId"];
115
- if (userId) {
116
- this.app.emit("ws:sendToTag", {
117
- tagKey: "userId",
118
- tagValue: userId,
119
- message: {
120
- type: "async-tasks:status",
121
- payload: {
122
- taskId: task.taskId,
123
- status: task.toJSON().status
124
- }
133
+ if (!userId) return;
134
+ this.app.emit("ws:sendToTag", {
135
+ tagKey: "userId",
136
+ tagValue: userId,
137
+ message: {
138
+ type: "async-tasks:status",
139
+ payload: {
140
+ taskId: task.taskId,
141
+ status: task.toJSON().status
125
142
  }
126
- });
143
+ }
144
+ });
145
+ if (status.type !== "running" && status.type !== "pending") {
146
+ const throttled = this.progressThrottles.get(task.taskId);
147
+ if (throttled) {
148
+ throttled.cancel();
149
+ this.progressThrottles.delete(task.taskId);
150
+ }
127
151
  }
128
- });
129
- asyncTaskManager.on("taskStatusChange", ({ status }) => {
130
152
  if (status.type === "success") {
131
153
  this.app.emit("workflow:dispatch");
132
154
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "异步任务管理器",
5
5
  "description": "Manage and monitor asynchronous tasks such as data import/export. Support task progress tracking and notification.",
6
6
  "description.zh-CN": "管理和监控数据导入导出等异步任务。支持任务进度跟踪和通知。",
7
- "version": "1.6.0-alpha.8",
7
+ "version": "1.6.0-alpha.9",
8
8
  "main": "dist/server/index.js",
9
9
  "peerDependencies": {
10
10
  "@nocobase/client": "1.x",
@@ -12,5 +12,5 @@
12
12
  "@nocobase/server": "1.x",
13
13
  "@nocobase/test": "1.x"
14
14
  },
15
- "gitHead": "f7ab757a5d7fb723c96bc9c1340291e4deec03ea"
15
+ "gitHead": "c6136fc6c9a2daab33fb1a20716cd9768e9a147f"
16
16
  }