@nocobase/plugin-async-task-manager 1.9.0-beta.5 → 1.9.0-beta.7
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/ISSUES.md +31 -0
- package/dist/client/index.d.ts +17 -4
- package/dist/client/index.js +1 -1
- package/dist/client/locale.d.ts +9 -1
- package/dist/common/collections/asyncTasks.d.ts +25 -0
- package/dist/common/collections/asyncTasks.js +97 -0
- package/dist/common/constants.d.ts +73 -0
- package/dist/common/constants.js +86 -0
- package/dist/common/types.d.ts +11 -0
- package/dist/common/types.js +24 -0
- package/dist/externalVersion.js +7 -5
- package/dist/server/base-task-manager.d.ts +21 -15
- package/dist/server/base-task-manager.js +230 -101
- package/dist/server/collections/asyncTasks.d.ts +11 -0
- package/dist/server/collections/asyncTasks.js +43 -0
- package/dist/server/command-task-type.d.ts +9 -0
- package/dist/server/command-task-type.js +19 -8
- package/dist/server/interfaces/async-task-manager.d.ts +11 -48
- package/dist/server/interfaces/task.d.ts +25 -23
- package/dist/server/interfaces/task.js +28 -0
- package/dist/server/plugin.d.ts +2 -5
- package/dist/server/plugin.js +15 -129
- package/dist/server/resourcers/async-tasks.d.ts +3 -2
- package/dist/server/resourcers/async-tasks.js +44 -27
- package/dist/server/task-type.d.ts +10 -62
- package/dist/server/task-type.js +66 -121
- package/package.json +2 -2
- package/dist/client/TaskResultRendererManager.d.ts +0 -6
- package/dist/node_modules/p-queue/dist/index.d.ts +0 -101
- package/dist/node_modules/p-queue/dist/index.js +0 -1
- package/dist/node_modules/p-queue/dist/lower-bound.d.ts +0 -1
- package/dist/node_modules/p-queue/dist/lower-bound.js +0 -21
- package/dist/node_modules/p-queue/dist/options.d.ts +0 -64
- package/dist/node_modules/p-queue/dist/options.js +0 -2
- package/dist/node_modules/p-queue/dist/priority-queue.d.ts +0 -12
- package/dist/node_modules/p-queue/dist/priority-queue.js +0 -32
- package/dist/node_modules/p-queue/dist/queue.d.ts +0 -7
- package/dist/node_modules/p-queue/dist/queue.js +0 -2
- package/dist/node_modules/p-queue/license +0 -9
- package/dist/node_modules/p-queue/node_modules/eventemitter3/index.d.ts +0 -134
- package/dist/node_modules/p-queue/node_modules/eventemitter3/index.js +0 -336
- package/dist/node_modules/p-queue/node_modules/eventemitter3/package.json +0 -56
- package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.js +0 -340
- package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.min.js +0 -1
- package/dist/node_modules/p-queue/package.json +0 -1
- package/dist/node_modules/uuid/dist/bin/uuid +0 -2
- package/dist/node_modules/uuid/dist/commonjs-browser/index.js +0 -79
- package/dist/node_modules/uuid/dist/commonjs-browser/md5.js +0 -223
- package/dist/node_modules/uuid/dist/commonjs-browser/native.js +0 -11
- package/dist/node_modules/uuid/dist/commonjs-browser/nil.js +0 -8
- package/dist/node_modules/uuid/dist/commonjs-browser/parse.js +0 -45
- package/dist/node_modules/uuid/dist/commonjs-browser/regex.js +0 -8
- package/dist/node_modules/uuid/dist/commonjs-browser/rng.js +0 -25
- package/dist/node_modules/uuid/dist/commonjs-browser/sha1.js +0 -104
- package/dist/node_modules/uuid/dist/commonjs-browser/stringify.js +0 -44
- package/dist/node_modules/uuid/dist/commonjs-browser/v1.js +0 -107
- package/dist/node_modules/uuid/dist/commonjs-browser/v3.js +0 -16
- package/dist/node_modules/uuid/dist/commonjs-browser/v35.js +0 -80
- package/dist/node_modules/uuid/dist/commonjs-browser/v4.js +0 -43
- package/dist/node_modules/uuid/dist/commonjs-browser/v5.js +0 -16
- package/dist/node_modules/uuid/dist/commonjs-browser/validate.js +0 -17
- package/dist/node_modules/uuid/dist/commonjs-browser/version.js +0 -21
- package/dist/node_modules/uuid/dist/esm-browser/index.js +0 -9
- package/dist/node_modules/uuid/dist/esm-browser/md5.js +0 -215
- package/dist/node_modules/uuid/dist/esm-browser/native.js +0 -4
- package/dist/node_modules/uuid/dist/esm-browser/nil.js +0 -1
- package/dist/node_modules/uuid/dist/esm-browser/parse.js +0 -35
- package/dist/node_modules/uuid/dist/esm-browser/regex.js +0 -1
- package/dist/node_modules/uuid/dist/esm-browser/rng.js +0 -18
- package/dist/node_modules/uuid/dist/esm-browser/sha1.js +0 -96
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js +0 -33
- package/dist/node_modules/uuid/dist/esm-browser/v1.js +0 -95
- package/dist/node_modules/uuid/dist/esm-browser/v3.js +0 -4
- package/dist/node_modules/uuid/dist/esm-browser/v35.js +0 -66
- package/dist/node_modules/uuid/dist/esm-browser/v4.js +0 -29
- package/dist/node_modules/uuid/dist/esm-browser/v5.js +0 -4
- package/dist/node_modules/uuid/dist/esm-browser/validate.js +0 -7
- package/dist/node_modules/uuid/dist/esm-browser/version.js +0 -11
- package/dist/node_modules/uuid/dist/esm-node/index.js +0 -9
- package/dist/node_modules/uuid/dist/esm-node/md5.js +0 -13
- package/dist/node_modules/uuid/dist/esm-node/native.js +0 -4
- package/dist/node_modules/uuid/dist/esm-node/nil.js +0 -1
- package/dist/node_modules/uuid/dist/esm-node/parse.js +0 -35
- package/dist/node_modules/uuid/dist/esm-node/regex.js +0 -1
- package/dist/node_modules/uuid/dist/esm-node/rng.js +0 -12
- package/dist/node_modules/uuid/dist/esm-node/sha1.js +0 -13
- package/dist/node_modules/uuid/dist/esm-node/stringify.js +0 -33
- package/dist/node_modules/uuid/dist/esm-node/v1.js +0 -95
- package/dist/node_modules/uuid/dist/esm-node/v3.js +0 -4
- package/dist/node_modules/uuid/dist/esm-node/v35.js +0 -66
- package/dist/node_modules/uuid/dist/esm-node/v4.js +0 -29
- package/dist/node_modules/uuid/dist/esm-node/v5.js +0 -4
- package/dist/node_modules/uuid/dist/esm-node/validate.js +0 -7
- package/dist/node_modules/uuid/dist/esm-node/version.js +0 -11
- package/dist/node_modules/uuid/dist/index.js +0 -1
- package/dist/node_modules/uuid/dist/md5-browser.js +0 -223
- package/dist/node_modules/uuid/dist/md5.js +0 -23
- package/dist/node_modules/uuid/dist/native-browser.js +0 -11
- package/dist/node_modules/uuid/dist/native.js +0 -15
- package/dist/node_modules/uuid/dist/nil.js +0 -8
- package/dist/node_modules/uuid/dist/parse.js +0 -45
- package/dist/node_modules/uuid/dist/regex.js +0 -8
- package/dist/node_modules/uuid/dist/rng-browser.js +0 -25
- package/dist/node_modules/uuid/dist/rng.js +0 -24
- package/dist/node_modules/uuid/dist/sha1-browser.js +0 -104
- package/dist/node_modules/uuid/dist/sha1.js +0 -23
- package/dist/node_modules/uuid/dist/stringify.js +0 -44
- package/dist/node_modules/uuid/dist/uuid-bin.js +0 -85
- package/dist/node_modules/uuid/dist/v1.js +0 -107
- package/dist/node_modules/uuid/dist/v3.js +0 -16
- package/dist/node_modules/uuid/dist/v35.js +0 -80
- package/dist/node_modules/uuid/dist/v4.js +0 -43
- package/dist/node_modules/uuid/dist/v5.js +0 -16
- package/dist/node_modules/uuid/dist/validate.js +0 -17
- package/dist/node_modules/uuid/dist/version.js +0 -21
- package/dist/node_modules/uuid/package.json +0 -1
|
@@ -11,6 +11,10 @@ var __defProp = Object.defineProperty;
|
|
|
11
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
14
18
|
var __copyProps = (to, from, except, desc) => {
|
|
15
19
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
20
|
for (let key of __getOwnPropNames(from))
|
|
@@ -21,4 +25,28 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
21
25
|
};
|
|
22
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
27
|
var task_exports = {};
|
|
28
|
+
__export(task_exports, {
|
|
29
|
+
TaskModel: () => TaskModel
|
|
30
|
+
});
|
|
24
31
|
module.exports = __toCommonJS(task_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
class TaskModel extends import_database.Model {
|
|
34
|
+
id;
|
|
35
|
+
origin;
|
|
36
|
+
type;
|
|
37
|
+
title;
|
|
38
|
+
params;
|
|
39
|
+
tags;
|
|
40
|
+
status;
|
|
41
|
+
progressTotal;
|
|
42
|
+
progressCurrent;
|
|
43
|
+
createdAt;
|
|
44
|
+
startedAt;
|
|
45
|
+
doneAt;
|
|
46
|
+
createdById;
|
|
47
|
+
// Additional fields can be added as needed
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
TaskModel
|
|
52
|
+
});
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -7,11 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Plugin } from '@nocobase/server';
|
|
10
|
-
export declare class
|
|
11
|
-
private progressThrottles;
|
|
12
|
-
afterAdd(): Promise<void>;
|
|
10
|
+
export declare class PluginAsyncTaskManagerServer extends Plugin {
|
|
13
11
|
beforeLoad(): Promise<void>;
|
|
14
|
-
getThrottledProgressEmitter(taskId: string, userId: string): Function;
|
|
15
12
|
load(): Promise<void>;
|
|
16
13
|
}
|
|
17
|
-
export default
|
|
14
|
+
export default PluginAsyncTaskManagerServer;
|
package/dist/server/plugin.js
CHANGED
|
@@ -36,149 +36,35 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var plugin_exports = {};
|
|
38
38
|
__export(plugin_exports, {
|
|
39
|
-
|
|
39
|
+
PluginAsyncTaskManagerServer: () => PluginAsyncTaskManagerServer,
|
|
40
40
|
default: () => plugin_default
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(plugin_exports);
|
|
43
43
|
var import_server = require("@nocobase/server");
|
|
44
|
-
var import_lodash = require("lodash");
|
|
45
44
|
var import_base_task_manager = require("./base-task-manager");
|
|
46
45
|
var import_command_task_type = require("./command-task-type");
|
|
47
46
|
var import_async_tasks = __toESM(require("./resourcers/async-tasks"));
|
|
48
|
-
class
|
|
49
|
-
progressThrottles = /* @__PURE__ */ new Map();
|
|
50
|
-
async afterAdd() {
|
|
51
|
-
}
|
|
47
|
+
class PluginAsyncTaskManagerServer extends import_server.Plugin {
|
|
52
48
|
async beforeLoad() {
|
|
53
|
-
this.app.container.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return manager;
|
|
58
|
-
});
|
|
59
|
-
this.app.container.get("AsyncTaskManager").registerTaskType(import_command_task_type.CommandTaskType);
|
|
60
|
-
this.app.acl.allow("asyncTasks", ["list", "get", "fetchFile", "cancel"], "loggedIn");
|
|
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
|
-
);
|
|
49
|
+
const existed = this.app.container.get("AsyncTaskManager");
|
|
50
|
+
if (existed) {
|
|
51
|
+
this.app.logger.warn("AsyncTaskManager already exists, skipping initialization.");
|
|
52
|
+
return;
|
|
84
53
|
}
|
|
85
|
-
|
|
54
|
+
const manager = new import_base_task_manager.BaseTaskManager();
|
|
55
|
+
this.app.container.register("AsyncTaskManager", manager);
|
|
86
56
|
}
|
|
87
57
|
async load() {
|
|
58
|
+
const manager = this.app.container.get("AsyncTaskManager");
|
|
59
|
+
manager.setLogger(this.app.logger);
|
|
60
|
+
manager.setApp(this.app);
|
|
61
|
+
manager.registerTaskType(import_command_task_type.CommandTaskType);
|
|
88
62
|
this.app.resourceManager.define(import_async_tasks.default);
|
|
89
|
-
|
|
90
|
-
this.app.on(`ws:message:request:async-tasks:list`, async (message) => {
|
|
91
|
-
const { tags, clientId } = message;
|
|
92
|
-
this.app.logger.info(`Received request for async tasks with tags: ${JSON.stringify(tags)}`);
|
|
93
|
-
const userTag = tags == null ? void 0 : tags.find((tag) => tag.startsWith("userId#"));
|
|
94
|
-
const userId = userTag ? userTag.split("#")[1] : null;
|
|
95
|
-
if (userId) {
|
|
96
|
-
this.app.logger.info(`Fetching tasks for userId: ${userId}`);
|
|
97
|
-
const tasks = await asyncTaskManager.getTasksByTag("userId", userId);
|
|
98
|
-
this.app.logger.info(`Found ${tasks.length} tasks for userId: ${userId}`);
|
|
99
|
-
this.app.emit("ws:sendToClient", {
|
|
100
|
-
clientId,
|
|
101
|
-
message: {
|
|
102
|
-
type: "async-tasks",
|
|
103
|
-
payload: tasks.map((task) => task.toJSON())
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
} else {
|
|
107
|
-
this.app.logger.warn(`No userId found in message tags: ${JSON.stringify(tags)}`);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
asyncTaskManager.on("taskCreated", ({ task }) => {
|
|
111
|
-
const userId = task.tags["userId"];
|
|
112
|
-
if (userId) {
|
|
113
|
-
this.app.emit("ws:sendToTag", {
|
|
114
|
-
tagKey: "userId",
|
|
115
|
-
tagValue: userId,
|
|
116
|
-
message: {
|
|
117
|
-
type: "async-tasks:created",
|
|
118
|
-
payload: task.toJSON()
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
asyncTaskManager.on("taskProgress", ({ task, progress }) => {
|
|
124
|
-
const userId = task.tags["userId"];
|
|
125
|
-
if (userId) {
|
|
126
|
-
const throttledEmit = this.getThrottledProgressEmitter(task.taskId, userId);
|
|
127
|
-
throttledEmit(progress);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
asyncTaskManager.on("taskStatusChange", ({ task, status }) => {
|
|
131
|
-
const userId = task.tags["userId"];
|
|
132
|
-
if (!userId) return;
|
|
133
|
-
this.app.emit("ws:sendToTag", {
|
|
134
|
-
tagKey: "userId",
|
|
135
|
-
tagValue: userId,
|
|
136
|
-
message: {
|
|
137
|
-
type: "async-tasks:status",
|
|
138
|
-
payload: {
|
|
139
|
-
taskId: task.taskId,
|
|
140
|
-
status: task.toJSON().status
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
if (status.type !== "running" && status.type !== "pending") {
|
|
145
|
-
const throttled = this.progressThrottles.get(task.taskId);
|
|
146
|
-
if (throttled) {
|
|
147
|
-
throttled.cancel();
|
|
148
|
-
this.progressThrottles.delete(task.taskId);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (status.type === "success") {
|
|
152
|
-
this.app.emit("workflow:dispatch");
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
this.app.on("ws:message:request:async-tasks:cancel", async (message) => {
|
|
156
|
-
const { payload, tags } = message;
|
|
157
|
-
const { taskId } = payload;
|
|
158
|
-
const userTag = tags == null ? void 0 : tags.find((tag) => tag.startsWith("userId#"));
|
|
159
|
-
const userId = userTag ? userTag.split("#")[1] : null;
|
|
160
|
-
if (userId) {
|
|
161
|
-
const task = asyncTaskManager.getTask(taskId);
|
|
162
|
-
if (task.tags["userId"] != userId) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const cancelled = await asyncTaskManager.cancelTask(taskId);
|
|
166
|
-
if (cancelled) {
|
|
167
|
-
this.app.emit("ws:sendToTag", {
|
|
168
|
-
tagKey: "userId",
|
|
169
|
-
tagValue: userId,
|
|
170
|
-
message: {
|
|
171
|
-
type: "async-tasks:cancelled",
|
|
172
|
-
payload: { taskId }
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
});
|
|
63
|
+
this.app.acl.allow("asyncTasks", ["list", "get", "fetchFile", "stop"], "loggedIn");
|
|
178
64
|
}
|
|
179
65
|
}
|
|
180
|
-
var plugin_default =
|
|
66
|
+
var plugin_default = PluginAsyncTaskManagerServer;
|
|
181
67
|
// Annotate the CommonJS export names for ESM import in node:
|
|
182
68
|
0 && (module.exports = {
|
|
183
|
-
|
|
69
|
+
PluginAsyncTaskManagerServer
|
|
184
70
|
});
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
import { Context } from '@nocobase/actions';
|
|
9
10
|
declare const _default: {
|
|
10
11
|
name: string;
|
|
11
12
|
actions: {
|
|
12
13
|
list(ctx: any, next: any): Promise<void>;
|
|
13
14
|
get(ctx: any, next: any): Promise<void>;
|
|
14
|
-
|
|
15
|
-
fetchFile(ctx: any, next: any): Promise<
|
|
15
|
+
stop(ctx: Context, next: any): Promise<never>;
|
|
16
|
+
fetchFile(ctx: any, next: any): Promise<any>;
|
|
16
17
|
};
|
|
17
18
|
};
|
|
18
19
|
export default _default;
|
|
@@ -39,53 +39,70 @@ __export(async_tasks_exports, {
|
|
|
39
39
|
default: () => async_tasks_default
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(async_tasks_exports);
|
|
42
|
+
var import_actions = __toESM(require("@nocobase/actions"));
|
|
42
43
|
var import_fs = __toESM(require("fs"));
|
|
43
|
-
var import_lodash = __toESM(require("lodash"));
|
|
44
44
|
var import_path = require("path");
|
|
45
|
+
var import_constants = require("../../common/constants");
|
|
45
46
|
var async_tasks_default = {
|
|
46
47
|
name: "asyncTasks",
|
|
47
48
|
actions: {
|
|
48
49
|
async list(ctx, next) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
ctx.action.mergeParams({
|
|
51
|
+
filter: {
|
|
52
|
+
createdById: ctx.auth.user.id
|
|
53
|
+
},
|
|
54
|
+
blacklist: ["params"]
|
|
55
|
+
});
|
|
56
|
+
await import_actions.default.list(ctx, next);
|
|
54
57
|
},
|
|
55
58
|
async get(ctx, next) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
ctx.action.mergeParams({
|
|
60
|
+
filter: {
|
|
61
|
+
createdById: ctx.auth.user.id
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
await import_actions.default.get(ctx, next);
|
|
61
65
|
},
|
|
62
|
-
async
|
|
66
|
+
async stop(ctx, next) {
|
|
63
67
|
const { filterByTk } = ctx.action.params;
|
|
64
68
|
const userId = ctx.auth.user.id;
|
|
65
|
-
const
|
|
66
|
-
const task =
|
|
69
|
+
const TaskRepo = ctx.app.db.getRepository("asyncTasks");
|
|
70
|
+
const task = await TaskRepo.findOne({
|
|
71
|
+
where: {
|
|
72
|
+
id: filterByTk,
|
|
73
|
+
createdById: userId
|
|
74
|
+
}
|
|
75
|
+
});
|
|
67
76
|
if (!task) {
|
|
68
|
-
ctx.
|
|
69
|
-
await next();
|
|
70
|
-
return;
|
|
77
|
+
return ctx.throw(404, "Task not found");
|
|
71
78
|
}
|
|
72
|
-
if (task.
|
|
73
|
-
ctx.throw(
|
|
79
|
+
if (!task.cancelable) {
|
|
80
|
+
return ctx.throw(400, "Task cannot be canceled");
|
|
74
81
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
82
|
+
const taskManager = ctx.app.container.get("AsyncTaskManager");
|
|
83
|
+
await taskManager.cancelTask(task.id);
|
|
84
|
+
ctx.status = 202;
|
|
77
85
|
await next();
|
|
78
86
|
},
|
|
79
87
|
async fetchFile(ctx, next) {
|
|
80
88
|
const { filterByTk, filename } = ctx.action.params;
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
const userId = ctx.auth.user.id;
|
|
90
|
+
const TaskRepo = ctx.app.db.getRepository("asyncTasks");
|
|
91
|
+
const task = await TaskRepo.findOne({
|
|
92
|
+
where: {
|
|
93
|
+
id: filterByTk,
|
|
94
|
+
createdById: userId
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (!task) {
|
|
98
|
+
return ctx.throw(404, "Task not found");
|
|
99
|
+
}
|
|
100
|
+
if (task.status !== import_constants.TASK_STATUS.SUCCEEDED) {
|
|
101
|
+
return ctx.throw(400, "Task is not success status");
|
|
85
102
|
}
|
|
86
|
-
const { filePath } =
|
|
103
|
+
const { filePath } = task.result || {};
|
|
87
104
|
if (!filePath) {
|
|
88
|
-
throw
|
|
105
|
+
return ctx.throw(400, "not a file task");
|
|
89
106
|
}
|
|
90
107
|
ctx.body = import_fs.default.createReadStream(filePath);
|
|
91
108
|
let finalFileName = filename ? filename : (0, import_path.basename)(filePath);
|
|
@@ -6,47 +6,31 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
/// <reference types="node" />
|
|
10
|
-
import EventEmitter from 'events';
|
|
11
9
|
import { Logger } from '@nocobase/logger';
|
|
12
|
-
import {
|
|
13
|
-
import { ITask } from './interfaces/task';
|
|
10
|
+
import { ITask, TaskModel } from './interfaces/task';
|
|
14
11
|
import Application from '@nocobase/server';
|
|
15
|
-
export declare
|
|
16
|
-
|
|
12
|
+
export declare class TaskType implements ITask {
|
|
13
|
+
record: TaskModel;
|
|
17
14
|
static type: string;
|
|
18
15
|
static cancelable: boolean;
|
|
19
|
-
|
|
16
|
+
static defaults(data: any): any;
|
|
20
17
|
protected logger: Logger;
|
|
21
18
|
protected app: Application;
|
|
22
|
-
progress: {
|
|
23
|
-
total: number;
|
|
24
|
-
current: number;
|
|
25
|
-
};
|
|
26
|
-
startedAt: Date;
|
|
27
|
-
fulfilledAt: Date;
|
|
28
|
-
taskId: string;
|
|
29
|
-
tags: Record<string, string>;
|
|
30
|
-
createdAt: Date;
|
|
31
|
-
context?: any;
|
|
32
|
-
title: any;
|
|
33
19
|
protected abortController: AbortController;
|
|
34
|
-
|
|
35
|
-
get
|
|
36
|
-
constructor(
|
|
20
|
+
onProgress: (record: TaskModel) => void;
|
|
21
|
+
get isCanceled(): boolean;
|
|
22
|
+
constructor(record: TaskModel);
|
|
37
23
|
setLogger(logger: Logger): void;
|
|
38
24
|
setApp(app: Application): void;
|
|
39
|
-
setContext(context: any): void;
|
|
40
25
|
/**
|
|
41
26
|
* Cancel the task
|
|
42
27
|
*/
|
|
43
|
-
cancel(): Promise<
|
|
44
|
-
statusChange(status: TaskStatus): Promise<void>;
|
|
28
|
+
cancel(): Promise<this>;
|
|
45
29
|
/**
|
|
46
30
|
* Execute the task implementation
|
|
47
31
|
* @returns Promise that resolves with the task result
|
|
48
32
|
*/
|
|
49
|
-
|
|
33
|
+
execute(): Promise<any>;
|
|
50
34
|
/**
|
|
51
35
|
* Report task progress
|
|
52
36
|
* @param progress Progress information containing total and current values
|
|
@@ -64,41 +48,5 @@ export declare abstract class TaskType extends EventEmitter implements ITask {
|
|
|
64
48
|
* - Event emission
|
|
65
49
|
*/
|
|
66
50
|
run(): Promise<void>;
|
|
67
|
-
|
|
68
|
-
toJSON(options?: {
|
|
69
|
-
raw?: boolean;
|
|
70
|
-
}): {
|
|
71
|
-
cancelable: boolean;
|
|
72
|
-
taskId: string;
|
|
73
|
-
status: {
|
|
74
|
-
type: "pending";
|
|
75
|
-
indicator?: "spinner";
|
|
76
|
-
} | {
|
|
77
|
-
type: "success";
|
|
78
|
-
indicator?: "success";
|
|
79
|
-
resultType?: "file" | "data";
|
|
80
|
-
payload?: any;
|
|
81
|
-
} | {
|
|
82
|
-
type: "running";
|
|
83
|
-
indicator: "progress";
|
|
84
|
-
} | {
|
|
85
|
-
type: "failed";
|
|
86
|
-
indicator?: "error";
|
|
87
|
-
errors: {
|
|
88
|
-
message: string;
|
|
89
|
-
code?: number;
|
|
90
|
-
}[];
|
|
91
|
-
} | {
|
|
92
|
-
type: "cancelled";
|
|
93
|
-
};
|
|
94
|
-
progress: {
|
|
95
|
-
total: number;
|
|
96
|
-
current: number;
|
|
97
|
-
};
|
|
98
|
-
tags: Record<string, string>;
|
|
99
|
-
createdAt: Date;
|
|
100
|
-
startedAt: Date;
|
|
101
|
-
fulfilledAt: Date;
|
|
102
|
-
title: any;
|
|
103
|
-
};
|
|
51
|
+
toJSON(): any;
|
|
104
52
|
}
|