@nocobase/plugin-workflow-javascript 2.1.36 → 2.1.38
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/dist/client/ScriptInstruction.d.ts +8 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +1 -1
- package/dist/common/constants.d.ts +9 -0
- package/dist/common/constants.js +36 -0
- package/dist/externalVersion.js +5 -4
- package/dist/node_modules/joi/package.json +1 -1
- package/dist/node_modules/winston-transport/package.json +1 -1
- package/dist/server/RunningJobs.d.ts +34 -0
- package/dist/server/RunningJobs.js +105 -0
- package/dist/server/ScriptInstruction.d.ts +9 -21
- package/dist/server/ScriptInstruction.js +44 -134
- package/dist/server/ScriptWorkerRunner.d.ts +27 -0
- package/dist/server/ScriptWorkerRunner.js +140 -0
- package/dist/server/TaskConsumer.d.ts +29 -0
- package/dist/server/TaskConsumer.js +317 -0
- package/dist/server/TaskRecovery.d.ts +22 -0
- package/dist/server/TaskRecovery.js +133 -0
- package/dist/server/constants.d.ts +9 -0
- package/dist/server/constants.js +36 -0
- package/dist/server/plugin.d.ts +14 -0
- package/dist/server/plugin.js +92 -2
- package/package.json +2 -2
|
@@ -39,102 +39,23 @@ __export(ScriptInstruction_exports, {
|
|
|
39
39
|
default: () => ScriptInstruction
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(ScriptInstruction_exports);
|
|
42
|
-
var import_node_events = require("node:events");
|
|
43
|
-
var import_node_path = __toESM(require("node:path"));
|
|
44
|
-
var import_node_worker_threads = require("node:worker_threads");
|
|
45
42
|
var import_winston = __toESM(require("winston"));
|
|
46
43
|
var import_joi = __toESM(require("joi"));
|
|
47
44
|
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
48
45
|
var import_cache_logger = require("./cache-logger");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
var import_constants = require("./constants");
|
|
47
|
+
var import_RunningJobs = require("./RunningJobs");
|
|
48
|
+
var import_ScriptWorkerRunner = require("./ScriptWorkerRunner");
|
|
52
49
|
class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*/
|
|
50
|
+
constructor(workflow, runningJobs) {
|
|
51
|
+
super(workflow);
|
|
52
|
+
this.runningJobs = runningJobs;
|
|
53
|
+
}
|
|
58
54
|
static get workerScript() {
|
|
59
|
-
|
|
60
|
-
return import_node_path.default.join(__dirname, hasModules ? "Vm.js" : "QuickJs.js");
|
|
55
|
+
return import_ScriptWorkerRunner.ScriptWorkerRunner.workerScript;
|
|
61
56
|
}
|
|
62
57
|
static async run(source, args, options) {
|
|
63
|
-
|
|
64
|
-
const worker = new import_node_worker_threads.Worker(this.workerScript, {
|
|
65
|
-
workerData: { source, args, options: timeout ? { timeout } : {} }
|
|
66
|
-
});
|
|
67
|
-
worker.stdout.on("data", (data) => {
|
|
68
|
-
logger.info(data.toString());
|
|
69
|
-
});
|
|
70
|
-
worker.stderr.on("data", (data) => {
|
|
71
|
-
logger.error(data.toString());
|
|
72
|
-
});
|
|
73
|
-
const outputClosed = Promise.all([(0, import_node_events.once)(worker.stdout, "close"), (0, import_node_events.once)(worker.stderr, "close")]);
|
|
74
|
-
const outcomePromise = new Promise((resolve) => {
|
|
75
|
-
const finish = (outcome2) => {
|
|
76
|
-
worker.removeListener("message", messageListener);
|
|
77
|
-
worker.removeListener("error", errorListener);
|
|
78
|
-
worker.removeListener("exit", exitListener);
|
|
79
|
-
signal == null ? void 0 : signal.removeEventListener("abort", abortListener);
|
|
80
|
-
resolve(outcome2);
|
|
81
|
-
};
|
|
82
|
-
const messageListener = (message) => {
|
|
83
|
-
if (isWorkerResult(message)) {
|
|
84
|
-
finish({ type: "result", result: message.result });
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const errorListener = (error) => {
|
|
88
|
-
finish({ type: "error", error });
|
|
89
|
-
};
|
|
90
|
-
const exitListener = (code) => {
|
|
91
|
-
finish({ type: "exit", code });
|
|
92
|
-
};
|
|
93
|
-
const abortListener = () => {
|
|
94
|
-
finish({ type: "aborted" });
|
|
95
|
-
};
|
|
96
|
-
worker.on("message", messageListener);
|
|
97
|
-
worker.once("error", errorListener);
|
|
98
|
-
worker.once("exit", exitListener);
|
|
99
|
-
signal == null ? void 0 : signal.addEventListener("abort", abortListener, { once: true });
|
|
100
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
101
|
-
abortListener();
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
const outcome = await outcomePromise;
|
|
105
|
-
try {
|
|
106
|
-
if (outcome.type !== "exit") {
|
|
107
|
-
await worker.terminate();
|
|
108
|
-
}
|
|
109
|
-
await outputClosed;
|
|
110
|
-
} catch (e) {
|
|
111
|
-
if (outcome.type === "aborted" || (signal == null ? void 0 : signal.aborted)) {
|
|
112
|
-
throw signal.reason instanceof Error ? signal.reason : new import_plugin_workflow.WorkflowTimeoutError();
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
116
|
-
result: e instanceof Error ? e.message : String(e)
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
if (outcome.type === "aborted") {
|
|
120
|
-
throw (signal == null ? void 0 : signal.reason) instanceof Error ? signal.reason : new import_plugin_workflow.WorkflowTimeoutError();
|
|
121
|
-
}
|
|
122
|
-
if (outcome.type === "error") {
|
|
123
|
-
return {
|
|
124
|
-
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
125
|
-
result: outcome.error.message
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
if (outcome.type === "exit" && outcome.code !== 0) {
|
|
129
|
-
return {
|
|
130
|
-
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
131
|
-
result: `Worker stopped with exit code ${outcome.code}`
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
136
|
-
result: outcome.type === "result" ? outcome.result : void 0
|
|
137
|
-
};
|
|
58
|
+
return import_ScriptWorkerRunner.ScriptWorkerRunner.run(source, args, options);
|
|
138
59
|
}
|
|
139
60
|
configSchema = import_joi.default.object({
|
|
140
61
|
content: import_joi.default.string(),
|
|
@@ -148,6 +69,7 @@ class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
|
148
69
|
).optional()
|
|
149
70
|
});
|
|
150
71
|
async run(node, prevJob, processor, options) {
|
|
72
|
+
var _a, _b;
|
|
151
73
|
const { content = "", continue: cont, timeout } = node.config;
|
|
152
74
|
const args = processor.getParsedValue(node.config.arguments ?? [], node.id);
|
|
153
75
|
const _args = args.reduce((pre, item) => ({ ...pre, [item.name]: item.value }), {});
|
|
@@ -170,60 +92,48 @@ class ScriptInstruction extends import_plugin_workflow.Instruction {
|
|
|
170
92
|
status: cont ? import_plugin_workflow.JOB_STATUS.RESOLVED : result.status === import_plugin_workflow.JOB_STATUS.RESOLVED ? import_plugin_workflow.JOB_STATUS.RESOLVED : import_plugin_workflow.JOB_STATUS.ERROR
|
|
171
93
|
};
|
|
172
94
|
}
|
|
95
|
+
const meta = {
|
|
96
|
+
args: _args
|
|
97
|
+
};
|
|
173
98
|
const { id } = processor.saveJob({
|
|
174
99
|
status: import_plugin_workflow.JOB_STATUS.PENDING,
|
|
175
100
|
nodeId: node.id,
|
|
176
101
|
nodeKey: node.key,
|
|
177
|
-
upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
|
|
102
|
+
upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null,
|
|
103
|
+
startedAt: null,
|
|
104
|
+
meta
|
|
178
105
|
});
|
|
179
|
-
|
|
180
|
-
|
|
106
|
+
const abortQueuedJob = async () => {
|
|
107
|
+
var _a2;
|
|
108
|
+
await this.runningJobs.abortAcrossInstances(this.workflow, {
|
|
109
|
+
type: import_RunningJobs.ABORT_JAVASCRIPT_JOB_SYNC_MESSAGE_TYPE,
|
|
110
|
+
jobId: id,
|
|
111
|
+
executionId: processor.execution.id,
|
|
112
|
+
reason: (0, import_RunningJobs.getAbortReason)((_a2 = options == null ? void 0 : options.signal) == null ? void 0 : _a2.reason)
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
if ((_a = options == null ? void 0 : options.signal) == null ? void 0 : _a.aborted) {
|
|
116
|
+
await abortQueuedJob();
|
|
117
|
+
} else {
|
|
118
|
+
(_b = options == null ? void 0 : options.signal) == null ? void 0 : _b.addEventListener(
|
|
119
|
+
"abort",
|
|
120
|
+
() => {
|
|
121
|
+
abortQueuedJob().catch((error) => {
|
|
122
|
+
processor.logger.error(`broadcasting JavaScript job (${id}) abort signal failed`, { error });
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
{ once: true }
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
processor.logger.info(`script (#${node.id}) has been queued, waiting for JavaScript Worker resource...`);
|
|
129
|
+
await processor.exit();
|
|
181
130
|
try {
|
|
182
|
-
await
|
|
131
|
+
await this.workflow.app.eventQueue.publish(import_constants.PENDING_JAVASCRIPT_TASK_CHANNEL, {
|
|
132
|
+
jobId: id
|
|
133
|
+
});
|
|
183
134
|
} catch (error) {
|
|
184
|
-
|
|
185
|
-
throw error;
|
|
135
|
+
processor.logger.error(`publishing JavaScript job (${id}) failed, recovery will republish it`, { error });
|
|
186
136
|
}
|
|
187
|
-
const jobResult = {
|
|
188
|
-
status: import_plugin_workflow.JOB_STATUS.PENDING
|
|
189
|
-
};
|
|
190
|
-
this.constructor.run(content, _args, { timeout, logger: processor.logger, signal: abortHandle.signal }).then((res) => {
|
|
191
|
-
if (res.status === import_plugin_workflow.JOB_STATUS.RESOLVED) {
|
|
192
|
-
processor.logger.info(`script (#${node.id}) get result success`);
|
|
193
|
-
jobResult.status = import_plugin_workflow.JOB_STATUS.RESOLVED;
|
|
194
|
-
jobResult.result = res.result;
|
|
195
|
-
processor.logger.info(`run script execution success, node id: ${node.id},the result is ${res.result}`);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (cont) {
|
|
199
|
-
processor.logger.warn(`script (#${node.id}) get result failed, the reason is ${res.result}`);
|
|
200
|
-
jobResult.status = import_plugin_workflow.JOB_STATUS.RESOLVED;
|
|
201
|
-
jobResult.result = res.result;
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
processor.logger.info(`script (#${node.id}) get result failed, the reason is ${res.result}`);
|
|
205
|
-
jobResult.status = import_plugin_workflow.JOB_STATUS.ERROR;
|
|
206
|
-
jobResult.result = res.result;
|
|
207
|
-
}).catch((e) => {
|
|
208
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
209
|
-
processor.logger.error(`script (#${node.id}) get result failed, the reason is ${message}`);
|
|
210
|
-
jobResult.status = import_plugin_workflow.JOB_STATUS.ERROR;
|
|
211
|
-
jobResult.result = message;
|
|
212
|
-
}).finally(() => {
|
|
213
|
-
abortHandle.dispose();
|
|
214
|
-
processor.logger.debug(`script (#${node.id}) ended, resume workflow...`);
|
|
215
|
-
setImmediate(async () => {
|
|
216
|
-
const job = await this.workflow.db.getRepository("jobs").findOne({ filterByTk: id });
|
|
217
|
-
const execution = await job.getExecution();
|
|
218
|
-
if (execution.status !== 0) {
|
|
219
|
-
processor.logger.warn(`script (#${node.id}) result discarded because execution (${execution.id}) is ended`);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
job.set(jobResult);
|
|
223
|
-
await this.workflow.resume(job).catch(() => {
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
137
|
}
|
|
228
138
|
async resume(node, job, processor) {
|
|
229
139
|
return job;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Logger } from 'winston';
|
|
10
|
+
export type ScriptArguments = Record<string, unknown> | unknown[] | null;
|
|
11
|
+
export type ScriptRunResult = {
|
|
12
|
+
status: number;
|
|
13
|
+
result?: unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare class ScriptWorkerRunner {
|
|
16
|
+
/**
|
|
17
|
+
* Returns the worker script path based on whether WORKFLOW_SCRIPT_MODULES is configured.
|
|
18
|
+
* - WORKFLOW_SCRIPT_MODULES set: uses Node.js vm with require support (unsafe; not a security boundary)
|
|
19
|
+
* - WORKFLOW_SCRIPT_MODULES unset: uses QuickJS (WASM) for maximum security (no require, no Node.js APIs)
|
|
20
|
+
*/
|
|
21
|
+
static get workerScript(): string;
|
|
22
|
+
static run(source: string, args: ScriptArguments, options: {
|
|
23
|
+
logger: Logger;
|
|
24
|
+
timeout?: number;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}): Promise<ScriptRunResult>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var ScriptWorkerRunner_exports = {};
|
|
38
|
+
__export(ScriptWorkerRunner_exports, {
|
|
39
|
+
ScriptWorkerRunner: () => ScriptWorkerRunner
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(ScriptWorkerRunner_exports);
|
|
42
|
+
var import_node_events = require("node:events");
|
|
43
|
+
var import_node_path = __toESM(require("node:path"));
|
|
44
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
45
|
+
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
46
|
+
function isWorkerResult(message) {
|
|
47
|
+
return typeof message === "object" && message !== null && "type" in message && message.type === "result";
|
|
48
|
+
}
|
|
49
|
+
class ScriptWorkerRunner {
|
|
50
|
+
/**
|
|
51
|
+
* Returns the worker script path based on whether WORKFLOW_SCRIPT_MODULES is configured.
|
|
52
|
+
* - WORKFLOW_SCRIPT_MODULES set: uses Node.js vm with require support (unsafe; not a security boundary)
|
|
53
|
+
* - WORKFLOW_SCRIPT_MODULES unset: uses QuickJS (WASM) for maximum security (no require, no Node.js APIs)
|
|
54
|
+
*/
|
|
55
|
+
static get workerScript() {
|
|
56
|
+
const hasModules = (process.env.WORKFLOW_SCRIPT_MODULES ?? "").split(",").filter(Boolean).length > 0;
|
|
57
|
+
return import_node_path.default.join(__dirname, hasModules ? "Vm.js" : "QuickJs.js");
|
|
58
|
+
}
|
|
59
|
+
static async run(source, args, options) {
|
|
60
|
+
const { logger, timeout, signal } = options;
|
|
61
|
+
const worker = new import_node_worker_threads.Worker(this.workerScript, {
|
|
62
|
+
workerData: { source, args, options: timeout ? { timeout } : {} }
|
|
63
|
+
});
|
|
64
|
+
worker.stdout.on("data", (data) => {
|
|
65
|
+
logger.info(data.toString());
|
|
66
|
+
});
|
|
67
|
+
worker.stderr.on("data", (data) => {
|
|
68
|
+
logger.error(data.toString());
|
|
69
|
+
});
|
|
70
|
+
const outputClosed = Promise.all([(0, import_node_events.once)(worker.stdout, "close"), (0, import_node_events.once)(worker.stderr, "close")]);
|
|
71
|
+
const outcomePromise = new Promise((resolve) => {
|
|
72
|
+
const finish = (outcome2) => {
|
|
73
|
+
worker.removeListener("message", messageListener);
|
|
74
|
+
worker.removeListener("error", errorListener);
|
|
75
|
+
worker.removeListener("exit", exitListener);
|
|
76
|
+
signal == null ? void 0 : signal.removeEventListener("abort", abortListener);
|
|
77
|
+
resolve(outcome2);
|
|
78
|
+
};
|
|
79
|
+
const messageListener = (message) => {
|
|
80
|
+
if (isWorkerResult(message)) {
|
|
81
|
+
finish({ type: "result", result: message.result });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const errorListener = (error) => {
|
|
85
|
+
finish({ type: "error", error });
|
|
86
|
+
};
|
|
87
|
+
const exitListener = (code) => {
|
|
88
|
+
finish({ type: "exit", code });
|
|
89
|
+
};
|
|
90
|
+
const abortListener = () => {
|
|
91
|
+
finish({ type: "aborted" });
|
|
92
|
+
};
|
|
93
|
+
worker.on("message", messageListener);
|
|
94
|
+
worker.once("error", errorListener);
|
|
95
|
+
worker.once("exit", exitListener);
|
|
96
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortListener, { once: true });
|
|
97
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
98
|
+
abortListener();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const outcome = await outcomePromise;
|
|
102
|
+
try {
|
|
103
|
+
if (outcome.type !== "exit") {
|
|
104
|
+
await worker.terminate();
|
|
105
|
+
}
|
|
106
|
+
await outputClosed;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (outcome.type === "aborted" || (signal == null ? void 0 : signal.aborted)) {
|
|
109
|
+
throw signal.reason instanceof Error ? signal.reason : new import_plugin_workflow.WorkflowTimeoutError();
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
113
|
+
result: error instanceof Error ? error.message : String(error)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (outcome.type === "aborted") {
|
|
117
|
+
throw (signal == null ? void 0 : signal.reason) instanceof Error ? signal.reason : new import_plugin_workflow.WorkflowTimeoutError();
|
|
118
|
+
}
|
|
119
|
+
if (outcome.type === "error") {
|
|
120
|
+
return {
|
|
121
|
+
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
122
|
+
result: outcome.error.message
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (outcome.type === "exit" && outcome.code !== 0) {
|
|
126
|
+
return {
|
|
127
|
+
status: import_plugin_workflow.JOB_STATUS.ERROR,
|
|
128
|
+
result: `Worker stopped with exit code ${outcome.code}`
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
status: import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
133
|
+
result: outcome.type === "result" ? outcome.result : void 0
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
ScriptWorkerRunner
|
|
140
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import type WorkflowPlugin from '@nocobase/plugin-workflow';
|
|
10
|
+
import type { QueueEventOptions } from '@nocobase/server';
|
|
11
|
+
import { RunningJobs } from './RunningJobs';
|
|
12
|
+
export declare class TaskConsumer {
|
|
13
|
+
private readonly workflowPlugin;
|
|
14
|
+
private readonly runningJobs;
|
|
15
|
+
private ready;
|
|
16
|
+
private closing;
|
|
17
|
+
private readonly processing;
|
|
18
|
+
constructor(workflowPlugin: WorkflowPlugin, runningJobs: RunningJobs);
|
|
19
|
+
setReady(ready: boolean): void;
|
|
20
|
+
idle(): boolean;
|
|
21
|
+
beforeStop(): Promise<void>;
|
|
22
|
+
readonly process: QueueEventOptions['process'];
|
|
23
|
+
private processWithPermit;
|
|
24
|
+
private claimJob;
|
|
25
|
+
private finishClaimedJob;
|
|
26
|
+
private settleClaimedJob;
|
|
27
|
+
private updatePendingJob;
|
|
28
|
+
private startClaimHeartbeat;
|
|
29
|
+
}
|