@nocobase/plugin-async-task-manager 1.9.0-beta.4 → 1.9.0-beta.6
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
package/dist/server/task-type.js
CHANGED
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var __create = Object.create;
|
|
11
10
|
var __defProp = Object.defineProperty;
|
|
12
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
14
|
var __export = (target, all) => {
|
|
17
15
|
for (var name in all)
|
|
@@ -25,57 +23,29 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
23
|
}
|
|
26
24
|
return to;
|
|
27
25
|
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
27
|
var task_type_exports = {};
|
|
38
28
|
__export(task_type_exports, {
|
|
39
29
|
TaskType: () => TaskType
|
|
40
30
|
});
|
|
41
31
|
module.exports = __toCommonJS(task_type_exports);
|
|
42
|
-
var import_uuid = require("uuid");
|
|
43
|
-
var import_events = __toESM(require("events"));
|
|
44
32
|
var import_async_task_manager = require("./interfaces/async-task-manager");
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.options = options;
|
|
50
|
-
this.status = {
|
|
51
|
-
type: "pending",
|
|
52
|
-
indicator: "spinner"
|
|
53
|
-
};
|
|
54
|
-
this.taskId = (0, import_uuid.v4)();
|
|
55
|
-
this.tags = tags || {};
|
|
56
|
-
this.createdAt = /* @__PURE__ */ new Date();
|
|
57
|
-
(_a = this.options.argv) == null ? void 0 : _a.push(`--taskId=${this.taskId}`);
|
|
33
|
+
var import_constants = require("../common/constants");
|
|
34
|
+
class TaskType {
|
|
35
|
+
constructor(record) {
|
|
36
|
+
this.record = record;
|
|
58
37
|
}
|
|
59
38
|
static type;
|
|
60
39
|
static cancelable = true;
|
|
61
|
-
|
|
40
|
+
static defaults(data) {
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
62
43
|
logger;
|
|
63
44
|
app;
|
|
64
|
-
progress = {
|
|
65
|
-
total: 0,
|
|
66
|
-
current: 0
|
|
67
|
-
};
|
|
68
|
-
startedAt;
|
|
69
|
-
fulfilledAt;
|
|
70
|
-
taskId;
|
|
71
|
-
tags;
|
|
72
|
-
createdAt;
|
|
73
|
-
context;
|
|
74
|
-
title;
|
|
75
45
|
abortController = new AbortController();
|
|
76
|
-
|
|
77
|
-
get
|
|
78
|
-
return this.
|
|
46
|
+
onProgress;
|
|
47
|
+
get isCanceled() {
|
|
48
|
+
return this.record.status === import_constants.TASK_STATUS.CANCELED;
|
|
79
49
|
}
|
|
80
50
|
setLogger(logger) {
|
|
81
51
|
this.logger = logger;
|
|
@@ -83,32 +53,41 @@ class TaskType extends import_events.default {
|
|
|
83
53
|
setApp(app) {
|
|
84
54
|
this.app = app;
|
|
85
55
|
}
|
|
86
|
-
setContext(context) {
|
|
87
|
-
this.context = context;
|
|
88
|
-
}
|
|
89
56
|
/**
|
|
90
57
|
* Cancel the task
|
|
91
58
|
*/
|
|
92
59
|
async cancel() {
|
|
93
60
|
var _a;
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
61
|
+
if (this.record.status === import_constants.TASK_STATUS.RUNNING) {
|
|
62
|
+
this.abortController.abort();
|
|
63
|
+
}
|
|
64
|
+
if (this.isCanceled) {
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`Task ${this.record.id} cancelled`);
|
|
68
|
+
return this;
|
|
98
69
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Execute the task implementation
|
|
72
|
+
* @returns Promise that resolves with the task result
|
|
73
|
+
*/
|
|
74
|
+
execute() {
|
|
75
|
+
return Promise.resolve();
|
|
102
76
|
}
|
|
103
77
|
/**
|
|
104
78
|
* Report task progress
|
|
105
79
|
* @param progress Progress information containing total and current values
|
|
106
80
|
*/
|
|
107
81
|
reportProgress(progress) {
|
|
108
|
-
var _a;
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
82
|
+
var _a, _b;
|
|
83
|
+
this.record.set({
|
|
84
|
+
progressTotal: progress.total,
|
|
85
|
+
progressCurrent: progress.current
|
|
86
|
+
});
|
|
87
|
+
(_a = this.logger) == null ? void 0 : _a.trace(
|
|
88
|
+
`Task ${this.record.id} progress update - current: ${progress.current}, total: ${progress.total}`
|
|
89
|
+
);
|
|
90
|
+
(_b = this.onProgress) == null ? void 0 : _b.call(this, this.record);
|
|
112
91
|
}
|
|
113
92
|
/**
|
|
114
93
|
* Run the task
|
|
@@ -120,82 +99,48 @@ class TaskType extends import_events.default {
|
|
|
120
99
|
*/
|
|
121
100
|
async run() {
|
|
122
101
|
var _a, _b, _c, _d, _e, _f;
|
|
123
|
-
this.
|
|
124
|
-
(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
if (this._isCancelled) {
|
|
132
|
-
(_b = this.logger) == null ? void 0 : _b.info(`Task ${this.taskId} was cancelled before execution`);
|
|
133
|
-
this.status = {
|
|
134
|
-
type: "cancelled"
|
|
135
|
-
};
|
|
136
|
-
this.emit("statusChange", this.status);
|
|
137
|
-
return;
|
|
102
|
+
(_a = this.logger) == null ? void 0 : _a.info(`Starting task ${this.record.id}, type: ${this.constructor.type}`);
|
|
103
|
+
if (this.isCanceled) {
|
|
104
|
+
(_b = this.logger) == null ? void 0 : _b.info(`Task ${this.record.id} was cancelled before execution`);
|
|
105
|
+
if (this.record.status !== import_constants.TASK_STATUS.CANCELED) {
|
|
106
|
+
await this.record.update({
|
|
107
|
+
status: import_constants.TASK_STATUS.CANCELED
|
|
108
|
+
});
|
|
138
109
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
await this.record.update({
|
|
113
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
114
|
+
status: import_constants.TASK_STATUS.RUNNING
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
const result = await this.execute();
|
|
118
|
+
(_c = this.logger) == null ? void 0 : _c.info(`Task ${this.record.id} completed successfully with result: ${JSON.stringify(result)}`);
|
|
119
|
+
await this.record.update({
|
|
120
|
+
status: import_constants.TASK_STATUS.SUCCEEDED,
|
|
121
|
+
doneAt: /* @__PURE__ */ new Date(),
|
|
122
|
+
result
|
|
123
|
+
});
|
|
148
124
|
} catch (error) {
|
|
149
125
|
if (error instanceof import_async_task_manager.CancelError) {
|
|
150
|
-
this.
|
|
151
|
-
(_d = this.logger) == null ? void 0 : _d.info(`Task ${this.taskId} was cancelled during execution`);
|
|
126
|
+
(_d = this.logger) == null ? void 0 : _d.info(`Task ${this.record.id} was cancelled during execution`);
|
|
152
127
|
return;
|
|
153
128
|
} else {
|
|
154
|
-
this.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
159
|
-
(_e = this.logger) == null ? void 0 : _e.error(`Task ${this.
|
|
160
|
-
|
|
129
|
+
await this.record.update({
|
|
130
|
+
status: import_constants.TASK_STATUS.FAILED,
|
|
131
|
+
doneAt: /* @__PURE__ */ new Date(),
|
|
132
|
+
error: error.toString()
|
|
133
|
+
});
|
|
134
|
+
(_e = this.logger) == null ? void 0 : _e.error(`Task ${this.record.id} failed with error: ${error.message}`);
|
|
135
|
+
throw error;
|
|
161
136
|
}
|
|
162
137
|
} finally {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
(_f = this.logger) == null ? void 0 : _f.info(`Task ${this.taskId} finished in ${duration}ms`);
|
|
138
|
+
const duration = this.record.doneAt.getTime() - this.record.startedAt.getTime();
|
|
139
|
+
(_f = this.logger) == null ? void 0 : _f.info(`Task ${this.record.id} finished in ${duration}ms`);
|
|
166
140
|
}
|
|
167
141
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (!errorHandlerPlugin || !this.context) {
|
|
171
|
-
return error.message;
|
|
172
|
-
}
|
|
173
|
-
const errorHandler = errorHandlerPlugin.errorHandler;
|
|
174
|
-
errorHandler.renderError(error, this.context);
|
|
175
|
-
return this.context.body.errors[0].message;
|
|
176
|
-
}
|
|
177
|
-
toJSON(options) {
|
|
178
|
-
var _a;
|
|
179
|
-
const json = {
|
|
180
|
-
cancelable: this.constructor.cancelable,
|
|
181
|
-
taskId: this.taskId,
|
|
182
|
-
status: { ...this.status },
|
|
183
|
-
progress: this.progress,
|
|
184
|
-
tags: this.tags,
|
|
185
|
-
createdAt: this.createdAt,
|
|
186
|
-
startedAt: this.startedAt,
|
|
187
|
-
fulfilledAt: this.fulfilledAt,
|
|
188
|
-
title: this.title
|
|
189
|
-
};
|
|
190
|
-
if (!(options == null ? void 0 : options.raw) && json.status.type === "success" && ((_a = json.status.payload) == null ? void 0 : _a.filePath)) {
|
|
191
|
-
json.status = {
|
|
192
|
-
type: "success",
|
|
193
|
-
indicator: "success",
|
|
194
|
-
resultType: "file",
|
|
195
|
-
payload: {}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
return json;
|
|
142
|
+
toJSON() {
|
|
143
|
+
return this.record.toJSON();
|
|
199
144
|
}
|
|
200
145
|
}
|
|
201
146
|
// Annotate the CommonJS export names for ESM import in node:
|
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.9.0-beta.
|
|
7
|
+
"version": "1.9.0-beta.6",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"peerDependencies": {
|
|
10
10
|
"@nocobase/client": "1.x",
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"p-queue": "^6.6.2"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "ada5e359a91135cb9baf605c04c5c380f067a046"
|
|
19
19
|
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import EventEmitter = require('eventemitter3');
|
|
2
|
-
import { Queue, RunFunction } from './queue';
|
|
3
|
-
import PriorityQueue from './priority-queue';
|
|
4
|
-
import { QueueAddOptions, DefaultAddOptions, Options } from './options';
|
|
5
|
-
declare type Task<TaskResultType> = (() => PromiseLike<TaskResultType>) | (() => TaskResultType);
|
|
6
|
-
/**
|
|
7
|
-
Promise queue with concurrency control.
|
|
8
|
-
*/
|
|
9
|
-
export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsType> = PriorityQueue, EnqueueOptionsType extends QueueAddOptions = DefaultAddOptions> extends EventEmitter<'active' | 'idle' | 'add' | 'next'> {
|
|
10
|
-
private readonly _carryoverConcurrencyCount;
|
|
11
|
-
private readonly _isIntervalIgnored;
|
|
12
|
-
private _intervalCount;
|
|
13
|
-
private readonly _intervalCap;
|
|
14
|
-
private readonly _interval;
|
|
15
|
-
private _intervalEnd;
|
|
16
|
-
private _intervalId?;
|
|
17
|
-
private _timeoutId?;
|
|
18
|
-
private _queue;
|
|
19
|
-
private readonly _queueClass;
|
|
20
|
-
private _pendingCount;
|
|
21
|
-
private _concurrency;
|
|
22
|
-
private _isPaused;
|
|
23
|
-
private _resolveEmpty;
|
|
24
|
-
private _resolveIdle;
|
|
25
|
-
private _timeout?;
|
|
26
|
-
private readonly _throwOnTimeout;
|
|
27
|
-
constructor(options?: Options<QueueType, EnqueueOptionsType>);
|
|
28
|
-
private get _doesIntervalAllowAnother();
|
|
29
|
-
private get _doesConcurrentAllowAnother();
|
|
30
|
-
private _next;
|
|
31
|
-
private _resolvePromises;
|
|
32
|
-
private _onResumeInterval;
|
|
33
|
-
private _isIntervalPaused;
|
|
34
|
-
private _tryToStartAnother;
|
|
35
|
-
private _initializeIntervalIfNeeded;
|
|
36
|
-
private _onInterval;
|
|
37
|
-
/**
|
|
38
|
-
Executes all queued functions until it reaches the limit.
|
|
39
|
-
*/
|
|
40
|
-
private _processQueue;
|
|
41
|
-
get concurrency(): number;
|
|
42
|
-
set concurrency(newConcurrency: number);
|
|
43
|
-
/**
|
|
44
|
-
Adds a sync or async task to the queue. Always returns a promise.
|
|
45
|
-
*/
|
|
46
|
-
add<TaskResultType>(fn: Task<TaskResultType>, options?: Partial<EnqueueOptionsType>): Promise<TaskResultType>;
|
|
47
|
-
/**
|
|
48
|
-
Same as `.add()`, but accepts an array of sync or async functions.
|
|
49
|
-
|
|
50
|
-
@returns A promise that resolves when all functions are resolved.
|
|
51
|
-
*/
|
|
52
|
-
addAll<TaskResultsType>(functions: ReadonlyArray<Task<TaskResultsType>>, options?: EnqueueOptionsType): Promise<TaskResultsType[]>;
|
|
53
|
-
/**
|
|
54
|
-
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
|
|
55
|
-
*/
|
|
56
|
-
start(): this;
|
|
57
|
-
/**
|
|
58
|
-
Put queue execution on hold.
|
|
59
|
-
*/
|
|
60
|
-
pause(): void;
|
|
61
|
-
/**
|
|
62
|
-
Clear the queue.
|
|
63
|
-
*/
|
|
64
|
-
clear(): void;
|
|
65
|
-
/**
|
|
66
|
-
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
67
|
-
|
|
68
|
-
@returns A promise that settles when the queue becomes empty.
|
|
69
|
-
*/
|
|
70
|
-
onEmpty(): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
|
|
73
|
-
|
|
74
|
-
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
75
|
-
*/
|
|
76
|
-
onIdle(): Promise<void>;
|
|
77
|
-
/**
|
|
78
|
-
Size of the queue.
|
|
79
|
-
*/
|
|
80
|
-
get size(): number;
|
|
81
|
-
/**
|
|
82
|
-
Size of the queue, filtered by the given options.
|
|
83
|
-
|
|
84
|
-
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
85
|
-
*/
|
|
86
|
-
sizeBy(options: Readonly<Partial<EnqueueOptionsType>>): number;
|
|
87
|
-
/**
|
|
88
|
-
Number of pending promises.
|
|
89
|
-
*/
|
|
90
|
-
get pending(): number;
|
|
91
|
-
/**
|
|
92
|
-
Whether the queue is currently paused.
|
|
93
|
-
*/
|
|
94
|
-
get isPaused(): boolean;
|
|
95
|
-
get timeout(): number | undefined;
|
|
96
|
-
/**
|
|
97
|
-
Set the timeout for future operations.
|
|
98
|
-
*/
|
|
99
|
-
set timeout(milliseconds: number | undefined);
|
|
100
|
-
}
|
|
101
|
-
export { Queue, QueueAddOptions, DefaultAddOptions, Options };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(){"use strict";var e={330:function(e){e.exports=(e,t)=>{t=t||(()=>{});return e.then((e=>new Promise((e=>{e(t())})).then((()=>e))),(e=>new Promise((e=>{e(t())})).then((()=>{throw e}))))}},291:function(e,t){Object.defineProperty(t,"__esModule",{value:true});function lowerBound(e,t,n){let r=0;let i=e.length;while(i>0){const s=i/2|0;let o=r+s;if(n(e[o],t)<=0){r=++o;i-=s+1}else{i=s}}return r}t["default"]=lowerBound},492:function(e,t,n){Object.defineProperty(t,"__esModule",{value:true});const r=n(291);class PriorityQueue{constructor(){this._queue=[]}enqueue(e,t){t=Object.assign({priority:0},t);const n={priority:t.priority,run:e};if(this.size&&this._queue[this.size-1].priority>=t.priority){this._queue.push(n);return}const i=r.default(this._queue,n,((e,t)=>t.priority-e.priority));this._queue.splice(i,0,n)}dequeue(){const e=this._queue.shift();return e===null||e===void 0?void 0:e.run}filter(e){return this._queue.filter((t=>t.priority===e.priority)).map((e=>e.run))}get size(){return this._queue.length}}t["default"]=PriorityQueue},924:function(e){var t=Object.prototype.hasOwnProperty,n="~";function Events(){}if(Object.create){Events.prototype=Object.create(null);if(!(new Events).__proto__)n=false}function EE(e,t,n){this.fn=e;this.context=t;this.once=n||false}function addListener(e,t,r,i,s){if(typeof r!=="function"){throw new TypeError("The listener must be a function")}var o=new EE(r,i||e,s),u=n?n+t:t;if(!e._events[u])e._events[u]=o,e._eventsCount++;else if(!e._events[u].fn)e._events[u].push(o);else e._events[u]=[e._events[u],o];return e}function clearEvent(e,t){if(--e._eventsCount===0)e._events=new Events;else delete e._events[t]}function EventEmitter(){this._events=new Events;this._eventsCount=0}EventEmitter.prototype.eventNames=function eventNames(){var e=[],r,i;if(this._eventsCount===0)return e;for(i in r=this._events){if(t.call(r,i))e.push(n?i.slice(1):i)}if(Object.getOwnPropertySymbols){return e.concat(Object.getOwnPropertySymbols(r))}return e};EventEmitter.prototype.listeners=function listeners(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,s=r.length,o=new Array(s);i<s;i++){o[i]=r[i].fn}return o};EventEmitter.prototype.listenerCount=function listenerCount(e){var t=n?n+e:e,r=this._events[t];if(!r)return 0;if(r.fn)return 1;return r.length};EventEmitter.prototype.emit=function emit(e,t,r,i,s,o){var u=n?n+e:e;if(!this._events[u])return false;var a=this._events[u],l=arguments.length,c,h;if(a.fn){if(a.once)this.removeListener(e,a.fn,undefined,true);switch(l){case 1:return a.fn.call(a.context),true;case 2:return a.fn.call(a.context,t),true;case 3:return a.fn.call(a.context,t,r),true;case 4:return a.fn.call(a.context,t,r,i),true;case 5:return a.fn.call(a.context,t,r,i,s),true;case 6:return a.fn.call(a.context,t,r,i,s,o),true}for(h=1,c=new Array(l-1);h<l;h++){c[h-1]=arguments[h]}a.fn.apply(a.context,c)}else{var _=a.length,f;for(h=0;h<_;h++){if(a[h].once)this.removeListener(e,a[h].fn,undefined,true);switch(l){case 1:a[h].fn.call(a[h].context);break;case 2:a[h].fn.call(a[h].context,t);break;case 3:a[h].fn.call(a[h].context,t,r);break;case 4:a[h].fn.call(a[h].context,t,r,i);break;default:if(!c)for(f=1,c=new Array(l-1);f<l;f++){c[f-1]=arguments[f]}a[h].fn.apply(a[h].context,c)}}}return true};EventEmitter.prototype.on=function on(e,t,n){return addListener(this,e,t,n,false)};EventEmitter.prototype.once=function once(e,t,n){return addListener(this,e,t,n,true)};EventEmitter.prototype.removeListener=function removeListener(e,t,r,i){var s=n?n+e:e;if(!this._events[s])return this;if(!t){clearEvent(this,s);return this}var o=this._events[s];if(o.fn){if(o.fn===t&&(!i||o.once)&&(!r||o.context===r)){clearEvent(this,s)}}else{for(var u=0,a=[],l=o.length;u<l;u++){if(o[u].fn!==t||i&&!o[u].once||r&&o[u].context!==r){a.push(o[u])}}if(a.length)this._events[s]=a.length===1?a[0]:a;else clearEvent(this,s)}return this};EventEmitter.prototype.removeAllListeners=function removeAllListeners(e){var t;if(e){t=n?n+e:e;if(this._events[t])clearEvent(this,t)}else{this._events=new Events;this._eventsCount=0}return this};EventEmitter.prototype.off=EventEmitter.prototype.removeListener;EventEmitter.prototype.addListener=EventEmitter.prototype.on;EventEmitter.prefixed=n;EventEmitter.EventEmitter=EventEmitter;if(true){e.exports=EventEmitter}},424:function(e,t,n){const r=n(330);class TimeoutError extends Error{constructor(e){super(e);this.name="TimeoutError"}}const pTimeout=(e,t,n)=>new Promise(((i,s)=>{if(typeof t!=="number"||t<0){throw new TypeError("Expected `milliseconds` to be a positive number")}if(t===Infinity){i(e);return}const o=setTimeout((()=>{if(typeof n==="function"){try{i(n())}catch(e){s(e)}return}const r=typeof n==="string"?n:`Promise timed out after ${t} milliseconds`;const o=n instanceof Error?n:new TimeoutError(r);if(typeof e.cancel==="function"){e.cancel()}s(o)}),t);r(e.then(i,s),(()=>{clearTimeout(o)}))}));e.exports=pTimeout;e.exports["default"]=pTimeout;e.exports.TimeoutError=TimeoutError}};var t={};function __nccwpck_require__(n){var r=t[n];if(r!==undefined){return r.exports}var i=t[n]={exports:{}};var s=true;try{e[n](i,i.exports,__nccwpck_require__);s=false}finally{if(s)delete t[n]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n={};!function(){var e=n;Object.defineProperty(e,"__esModule",{value:true});const t=__nccwpck_require__(924);const r=__nccwpck_require__(424);const i=__nccwpck_require__(492);const empty=()=>{};const s=new r.TimeoutError;class PQueue extends t{constructor(e){var t,n,r,s;super();this._intervalCount=0;this._intervalEnd=0;this._pendingCount=0;this._resolveEmpty=empty;this._resolveIdle=empty;e=Object.assign({carryoverConcurrencyCount:false,intervalCap:Infinity,interval:0,concurrency:Infinity,autoStart:true,queueClass:i.default},e);if(!(typeof e.intervalCap==="number"&&e.intervalCap>=1)){throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(n=(t=e.intervalCap)===null||t===void 0?void 0:t.toString())!==null&&n!==void 0?n:""}\` (${typeof e.intervalCap})`)}if(e.interval===undefined||!(Number.isFinite(e.interval)&&e.interval>=0)){throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(s=(r=e.interval)===null||r===void 0?void 0:r.toString())!==null&&s!==void 0?s:""}\` (${typeof e.interval})`)}this._carryoverConcurrencyCount=e.carryoverConcurrencyCount;this._isIntervalIgnored=e.intervalCap===Infinity||e.interval===0;this._intervalCap=e.intervalCap;this._interval=e.interval;this._queue=new e.queueClass;this._queueClass=e.queueClass;this.concurrency=e.concurrency;this._timeout=e.timeout;this._throwOnTimeout=e.throwOnTimeout===true;this._isPaused=e.autoStart===false}get _doesIntervalAllowAnother(){return this._isIntervalIgnored||this._intervalCount<this._intervalCap}get _doesConcurrentAllowAnother(){return this._pendingCount<this._concurrency}_next(){this._pendingCount--;this._tryToStartAnother();this.emit("next")}_resolvePromises(){this._resolveEmpty();this._resolveEmpty=empty;if(this._pendingCount===0){this._resolveIdle();this._resolveIdle=empty;this.emit("idle")}}_onResumeInterval(){this._onInterval();this._initializeIntervalIfNeeded();this._timeoutId=undefined}_isIntervalPaused(){const e=Date.now();if(this._intervalId===undefined){const t=this._intervalEnd-e;if(t<0){this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0}else{if(this._timeoutId===undefined){this._timeoutId=setTimeout((()=>{this._onResumeInterval()}),t)}return true}}return false}_tryToStartAnother(){if(this._queue.size===0){if(this._intervalId){clearInterval(this._intervalId)}this._intervalId=undefined;this._resolvePromises();return false}if(!this._isPaused){const e=!this._isIntervalPaused();if(this._doesIntervalAllowAnother&&this._doesConcurrentAllowAnother){const t=this._queue.dequeue();if(!t){return false}this.emit("active");t();if(e){this._initializeIntervalIfNeeded()}return true}}return false}_initializeIntervalIfNeeded(){if(this._isIntervalIgnored||this._intervalId!==undefined){return}this._intervalId=setInterval((()=>{this._onInterval()}),this._interval);this._intervalEnd=Date.now()+this._interval}_onInterval(){if(this._intervalCount===0&&this._pendingCount===0&&this._intervalId){clearInterval(this._intervalId);this._intervalId=undefined}this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0;this._processQueue()}_processQueue(){while(this._tryToStartAnother()){}}get concurrency(){return this._concurrency}set concurrency(e){if(!(typeof e==="number"&&e>=1)){throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`)}this._concurrency=e;this._processQueue()}async add(e,t={}){return new Promise(((n,i)=>{const run=async()=>{this._pendingCount++;this._intervalCount++;try{const o=this._timeout===undefined&&t.timeout===undefined?e():r.default(Promise.resolve(e()),t.timeout===undefined?this._timeout:t.timeout,(()=>{if(t.throwOnTimeout===undefined?this._throwOnTimeout:t.throwOnTimeout){i(s)}return undefined}));n(await o)}catch(e){i(e)}this._next()};this._queue.enqueue(run,t);this._tryToStartAnother();this.emit("add")}))}async addAll(e,t){return Promise.all(e.map((async e=>this.add(e,t))))}start(){if(!this._isPaused){return this}this._isPaused=false;this._processQueue();return this}pause(){this._isPaused=true}clear(){this._queue=new this._queueClass}async onEmpty(){if(this._queue.size===0){return}return new Promise((e=>{const t=this._resolveEmpty;this._resolveEmpty=()=>{t();e()}}))}async onIdle(){if(this._pendingCount===0&&this._queue.size===0){return}return new Promise((e=>{const t=this._resolveIdle;this._resolveIdle=()=>{t();e()}}))}get size(){return this._queue.size}sizeBy(e){return this._queue.filter(e).length}get pending(){return this._pendingCount}get isPaused(){return this._isPaused}get timeout(){return this._timeout}set timeout(e){this._timeout=e}}e["default"]=PQueue}();module.exports=n})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function lowerBound<T>(array: readonly T[], value: T, comparator: (a: T, b: T) => number): number;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
|
|
4
|
-
// Used to compute insertion index to keep queue sorted after insertion
|
|
5
|
-
function lowerBound(array, value, comparator) {
|
|
6
|
-
let first = 0;
|
|
7
|
-
let count = array.length;
|
|
8
|
-
while (count > 0) {
|
|
9
|
-
const step = (count / 2) | 0;
|
|
10
|
-
let it = first + step;
|
|
11
|
-
if (comparator(array[it], value) <= 0) {
|
|
12
|
-
first = ++it;
|
|
13
|
-
count -= step + 1;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
count = step;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return first;
|
|
20
|
-
}
|
|
21
|
-
exports.default = lowerBound;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Queue, RunFunction } from './queue';
|
|
2
|
-
export interface QueueAddOptions {
|
|
3
|
-
readonly [key: string]: unknown;
|
|
4
|
-
}
|
|
5
|
-
export interface Options<QueueType extends Queue<RunFunction, QueueOptions>, QueueOptions extends QueueAddOptions> {
|
|
6
|
-
/**
|
|
7
|
-
Concurrency limit.
|
|
8
|
-
|
|
9
|
-
Minimum: `1`.
|
|
10
|
-
|
|
11
|
-
@default Infinity
|
|
12
|
-
*/
|
|
13
|
-
readonly concurrency?: number;
|
|
14
|
-
/**
|
|
15
|
-
Whether queue tasks within concurrency limit, are auto-executed as soon as they're added.
|
|
16
|
-
|
|
17
|
-
@default true
|
|
18
|
-
*/
|
|
19
|
-
readonly autoStart?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
Class with a `enqueue` and `dequeue` method, and a `size` getter. See the [Custom QueueClass](https://github.com/sindresorhus/p-queue#custom-queueclass) section.
|
|
22
|
-
*/
|
|
23
|
-
readonly queueClass?: new () => QueueType;
|
|
24
|
-
/**
|
|
25
|
-
The max number of runs in the given interval of time.
|
|
26
|
-
|
|
27
|
-
Minimum: `1`.
|
|
28
|
-
|
|
29
|
-
@default Infinity
|
|
30
|
-
*/
|
|
31
|
-
readonly intervalCap?: number;
|
|
32
|
-
/**
|
|
33
|
-
The length of time in milliseconds before the interval count resets. Must be finite.
|
|
34
|
-
|
|
35
|
-
Minimum: `0`.
|
|
36
|
-
|
|
37
|
-
@default 0
|
|
38
|
-
*/
|
|
39
|
-
readonly interval?: number;
|
|
40
|
-
/**
|
|
41
|
-
Whether the task must finish in the given interval or will be carried over into the next interval count.
|
|
42
|
-
|
|
43
|
-
@default false
|
|
44
|
-
*/
|
|
45
|
-
readonly carryoverConcurrencyCount?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
48
|
-
*/
|
|
49
|
-
timeout?: number;
|
|
50
|
-
/**
|
|
51
|
-
Whether or not a timeout is considered an exception.
|
|
52
|
-
|
|
53
|
-
@default false
|
|
54
|
-
*/
|
|
55
|
-
throwOnTimeout?: boolean;
|
|
56
|
-
}
|
|
57
|
-
export interface DefaultAddOptions extends QueueAddOptions {
|
|
58
|
-
/**
|
|
59
|
-
Priority of operation. Operations with greater priority will be scheduled first.
|
|
60
|
-
|
|
61
|
-
@default 0
|
|
62
|
-
*/
|
|
63
|
-
readonly priority?: number;
|
|
64
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Queue, RunFunction } from './queue';
|
|
2
|
-
import { QueueAddOptions } from './options';
|
|
3
|
-
export interface PriorityQueueOptions extends QueueAddOptions {
|
|
4
|
-
priority?: number;
|
|
5
|
-
}
|
|
6
|
-
export default class PriorityQueue implements Queue<RunFunction, PriorityQueueOptions> {
|
|
7
|
-
private readonly _queue;
|
|
8
|
-
enqueue(run: RunFunction, options?: Partial<PriorityQueueOptions>): void;
|
|
9
|
-
dequeue(): RunFunction | undefined;
|
|
10
|
-
filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[];
|
|
11
|
-
get size(): number;
|
|
12
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const lower_bound_1 = require("./lower-bound");
|
|
4
|
-
class PriorityQueue {
|
|
5
|
-
constructor() {
|
|
6
|
-
this._queue = [];
|
|
7
|
-
}
|
|
8
|
-
enqueue(run, options) {
|
|
9
|
-
options = Object.assign({ priority: 0 }, options);
|
|
10
|
-
const element = {
|
|
11
|
-
priority: options.priority,
|
|
12
|
-
run
|
|
13
|
-
};
|
|
14
|
-
if (this.size && this._queue[this.size - 1].priority >= options.priority) {
|
|
15
|
-
this._queue.push(element);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const index = lower_bound_1.default(this._queue, element, (a, b) => b.priority - a.priority);
|
|
19
|
-
this._queue.splice(index, 0, element);
|
|
20
|
-
}
|
|
21
|
-
dequeue() {
|
|
22
|
-
const item = this._queue.shift();
|
|
23
|
-
return item === null || item === void 0 ? void 0 : item.run;
|
|
24
|
-
}
|
|
25
|
-
filter(options) {
|
|
26
|
-
return this._queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
27
|
-
}
|
|
28
|
-
get size() {
|
|
29
|
-
return this._queue.length;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.default = PriorityQueue;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare type RunFunction = () => Promise<unknown>;
|
|
2
|
-
export interface Queue<Element, Options> {
|
|
3
|
-
size: number;
|
|
4
|
-
filter: (options: Partial<Options>) => Element[];
|
|
5
|
-
dequeue: () => Element | undefined;
|
|
6
|
-
enqueue: (run: Element, options?: Partial<Options>) => void;
|
|
7
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|