@tachybase/module-worker-thread 1.1.16 → 1.1.20
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/externalVersion.js +8 -8
- package/dist/server/intercept.d.ts +1 -0
- package/dist/server/intercept.js +27 -0
- package/dist/server/worker.d.ts +1 -0
- package/dist/server/worker.js +10 -9
- package/dist/server/workerManager.js +15 -19
- package/package.json +10 -10
package/dist/externalVersion.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
"react": "18.3.1",
|
|
3
|
-
"@tachybase/client": "1.1.
|
|
4
|
-
"@tachybase/schema": "1.1.
|
|
3
|
+
"@tachybase/client": "1.1.20",
|
|
4
|
+
"@tachybase/schema": "1.1.20",
|
|
5
5
|
"antd": "5.22.5",
|
|
6
|
-
"@tachybase/server": "1.1.
|
|
7
|
-
"@tachybase/logger": "1.1.
|
|
8
|
-
"@tachybase/module-collection": "1.1.
|
|
9
|
-
"@tachybase/module-user": "1.1.
|
|
10
|
-
"@tachybase/utils": "1.1.
|
|
11
|
-
"@tachybase/actions": "1.1.
|
|
6
|
+
"@tachybase/server": "1.1.20",
|
|
7
|
+
"@tachybase/logger": "1.1.20",
|
|
8
|
+
"@tachybase/module-collection": "1.1.20",
|
|
9
|
+
"@tachybase/module-user": "1.1.20",
|
|
10
|
+
"@tachybase/utils": "1.1.20",
|
|
11
|
+
"@tachybase/actions": "1.1.20"
|
|
12
12
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var import_node_module = require("node:module");
|
|
2
|
+
var import_node_path = require("node:path");
|
|
3
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
4
|
+
if (!import_node_worker_threads.isMainThread && process.env.RUN_MODE === "engine") {
|
|
5
|
+
let isBareModule = function(name) {
|
|
6
|
+
return !name.startsWith(".") && !name.startsWith("/") && !(0, import_node_path.isAbsolute)(name);
|
|
7
|
+
};
|
|
8
|
+
const lookingPaths = process.env.TACHYBASE_WORKER_PATHS.split(",");
|
|
9
|
+
const originalLoad = import_node_module.Module._load;
|
|
10
|
+
process.env.TACHYBASE_WORKER_PATHS = lookingPaths.join(",");
|
|
11
|
+
import_node_module.Module._load = function(request, parent, isMain) {
|
|
12
|
+
if ((0, import_node_module.isBuiltin)(request)) {
|
|
13
|
+
return originalLoad(request, parent, isMain);
|
|
14
|
+
}
|
|
15
|
+
if (isBareModule(request)) {
|
|
16
|
+
try {
|
|
17
|
+
const resolvedFromApp = require.resolve(request, { paths: lookingPaths });
|
|
18
|
+
return originalLoad(resolvedFromApp, parent, isMain);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
if (err.code === "MODULE_NOT_FOUND") {
|
|
21
|
+
return originalLoad(request, parent, isMain);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return originalLoad(request, parent, isMain);
|
|
26
|
+
};
|
|
27
|
+
}
|
package/dist/server/worker.d.ts
CHANGED
package/dist/server/worker.js
CHANGED
|
@@ -30,7 +30,8 @@ __export(worker_exports, {
|
|
|
30
30
|
main: () => main
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(worker_exports);
|
|
33
|
-
var
|
|
33
|
+
var import_intercept = require("./intercept");
|
|
34
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
34
35
|
var import_logger = require("@tachybase/logger");
|
|
35
36
|
var import_module_collection = __toESM(require("@tachybase/module-collection"));
|
|
36
37
|
var import_module_user = __toESM(require("@tachybase/module-user"));
|
|
@@ -59,13 +60,13 @@ async function reloadCustomCollections(app) {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
const handleWorkerMessages = (app) => {
|
|
62
|
-
if (
|
|
63
|
+
if (import_node_worker_threads.isMainThread) {
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
import_node_worker_threads.parentPort.postMessage({
|
|
66
67
|
event: import_workerTypes.WorkerEvent.Started
|
|
67
68
|
});
|
|
68
|
-
|
|
69
|
+
import_node_worker_threads.parentPort.on("message", async (message) => {
|
|
69
70
|
var _a;
|
|
70
71
|
if ((_a = message.values) == null ? void 0 : _a.inputLog) {
|
|
71
72
|
app.logger.info("[worker] input", message.values.inputLog);
|
|
@@ -82,14 +83,14 @@ const handleWorkerMessages = (app) => {
|
|
|
82
83
|
}
|
|
83
84
|
const result = await appPlugin[method](params);
|
|
84
85
|
app.logger.info(`[worker] output for ${plugin}.${method}:`, result);
|
|
85
|
-
|
|
86
|
+
import_node_worker_threads.parentPort.postMessage({
|
|
86
87
|
event,
|
|
87
88
|
reqId,
|
|
88
89
|
result
|
|
89
90
|
});
|
|
90
91
|
} catch (error) {
|
|
91
92
|
app.logger.error("[worker] error", error);
|
|
92
|
-
|
|
93
|
+
import_node_worker_threads.parentPort.postMessage({
|
|
93
94
|
event,
|
|
94
95
|
reqId,
|
|
95
96
|
error
|
|
@@ -97,7 +98,7 @@ const handleWorkerMessages = (app) => {
|
|
|
97
98
|
}
|
|
98
99
|
} else {
|
|
99
100
|
app.logger.error("[worker] invalid message", message);
|
|
100
|
-
|
|
101
|
+
import_node_worker_threads.parentPort.postMessage({
|
|
101
102
|
event,
|
|
102
103
|
reqId,
|
|
103
104
|
error: "invalid message"
|
|
@@ -108,11 +109,11 @@ const handleWorkerMessages = (app) => {
|
|
|
108
109
|
const main = async () => {
|
|
109
110
|
var _a, _b, _c;
|
|
110
111
|
let app;
|
|
111
|
-
const appName =
|
|
112
|
+
const appName = import_node_worker_threads.workerData.appName || "main";
|
|
112
113
|
try {
|
|
113
114
|
const applicationOptions = {
|
|
114
115
|
name: `worker-${appName}-${(0, import_utils.uid)()}`,
|
|
115
|
-
database:
|
|
116
|
+
database: import_node_worker_threads.workerData.databaseOptions,
|
|
116
117
|
logger: loggerOptions
|
|
117
118
|
};
|
|
118
119
|
app = new import_server.Application(applicationOptions);
|
|
@@ -30,9 +30,9 @@ __export(workerManager_exports, {
|
|
|
30
30
|
WorkerManager: () => WorkerManager
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(workerManager_exports);
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
33
|
+
var import_node_crypto = require("node:crypto");
|
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
|
35
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
36
36
|
var import_utils = require("@tachybase/utils");
|
|
37
37
|
var import_constants = require("./constants");
|
|
38
38
|
var import_workerTypes = require("./workerTypes");
|
|
@@ -59,7 +59,7 @@ const _WorkerManager = class _WorkerManager {
|
|
|
59
59
|
this.busyWorkerSet = /* @__PURE__ */ new Set();
|
|
60
60
|
this.cache = /* @__PURE__ */ new Map();
|
|
61
61
|
this.errorRecoveryTimes = 0;
|
|
62
|
-
if (!
|
|
62
|
+
if (!import_node_worker_threads.isMainThread) {
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
if (workerNum !== void 0) {
|
|
@@ -86,10 +86,10 @@ const _WorkerManager = class _WorkerManager {
|
|
|
86
86
|
return this.busyWorkerSet.size;
|
|
87
87
|
}
|
|
88
88
|
async initWorkers() {
|
|
89
|
-
if (!
|
|
89
|
+
if (!import_node_worker_threads.isMainThread) {
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
|
-
this.isProd = await (0, import_utils.fsExists)(
|
|
92
|
+
this.isProd = await (0, import_utils.fsExists)(import_node_path.default.resolve(__dirname, `${import_constants.WORKER_FILE}.js`));
|
|
93
93
|
await Promise.all(Array.from({ length: this.workerNum }).map(() => this.addWorker()));
|
|
94
94
|
}
|
|
95
95
|
async addWorker() {
|
|
@@ -97,30 +97,26 @@ const _WorkerManager = class _WorkerManager {
|
|
|
97
97
|
const maxOldSpaceSize = `--max-old-space-size=${maxMemory}`;
|
|
98
98
|
let worker;
|
|
99
99
|
if (this.isProd) {
|
|
100
|
-
worker = new
|
|
100
|
+
worker = new import_node_worker_threads.Worker(import_node_path.default.resolve(__dirname, `${import_constants.WORKER_FILE}.js`), {
|
|
101
101
|
workerData: {
|
|
102
102
|
appName: this.app.name,
|
|
103
103
|
databaseOptions: this.databaseOptions
|
|
104
104
|
},
|
|
105
105
|
env: {
|
|
106
106
|
...process.env,
|
|
107
|
-
|
|
108
|
-
NODE_OPTIONS: maxOldSpaceSize
|
|
109
|
-
}
|
|
107
|
+
NODE_OPTIONS: maxOldSpaceSize
|
|
110
108
|
}
|
|
111
109
|
});
|
|
112
110
|
} else {
|
|
113
|
-
worker = new
|
|
111
|
+
worker = new import_node_worker_threads.Worker(import_node_path.default.resolve(__dirname, "../../worker-starter.mjs"), {
|
|
114
112
|
workerData: {
|
|
115
|
-
scriptPath:
|
|
113
|
+
scriptPath: import_node_path.default.resolve(__dirname, `${import_constants.WORKER_FILE}.ts`),
|
|
116
114
|
appName: this.app.name,
|
|
117
115
|
databaseOptions: this.databaseOptions
|
|
118
116
|
},
|
|
119
117
|
env: {
|
|
120
118
|
...process.env,
|
|
121
|
-
|
|
122
|
-
NODE_OPTIONS: maxOldSpaceSize
|
|
123
|
-
}
|
|
119
|
+
NODE_OPTIONS: maxOldSpaceSize
|
|
124
120
|
}
|
|
125
121
|
});
|
|
126
122
|
}
|
|
@@ -154,7 +150,7 @@ const _WorkerManager = class _WorkerManager {
|
|
|
154
150
|
});
|
|
155
151
|
}
|
|
156
152
|
async clear() {
|
|
157
|
-
if (!
|
|
153
|
+
if (!import_node_worker_threads.isMainThread) {
|
|
158
154
|
return;
|
|
159
155
|
}
|
|
160
156
|
await Promise.all(this.workerList.map((worker) => worker.terminate()));
|
|
@@ -168,7 +164,7 @@ const _WorkerManager = class _WorkerManager {
|
|
|
168
164
|
}
|
|
169
165
|
async resetWorkerNum(targetNum) {
|
|
170
166
|
var _a;
|
|
171
|
-
if (!
|
|
167
|
+
if (!import_node_worker_threads.isMainThread) {
|
|
172
168
|
return;
|
|
173
169
|
}
|
|
174
170
|
this.workerNum = targetNum;
|
|
@@ -192,7 +188,7 @@ const _WorkerManager = class _WorkerManager {
|
|
|
192
188
|
}
|
|
193
189
|
/** 强制重启所有线程 */
|
|
194
190
|
async restartAllForcely() {
|
|
195
|
-
if (!
|
|
191
|
+
if (!import_node_worker_threads.isMainThread) {
|
|
196
192
|
return;
|
|
197
193
|
}
|
|
198
194
|
const workerNum = this.workerNum;
|
|
@@ -315,7 +311,7 @@ const _WorkerManager = class _WorkerManager {
|
|
|
315
311
|
if (this.workerList.length === 0) {
|
|
316
312
|
throw new Error("No available workers");
|
|
317
313
|
}
|
|
318
|
-
const reqId = (0,
|
|
314
|
+
const reqId = (0, import_node_crypto.randomUUID)();
|
|
319
315
|
if (this.currentWorkerIndex >= this.workerList.length) {
|
|
320
316
|
this.currentWorkerIndex = 0;
|
|
321
317
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/module-worker-thread",
|
|
3
3
|
"displayName": "Worker thread",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.20",
|
|
5
5
|
"description": "Worker thread for executing time-consuming tasks",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Workflow"
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"tsx": "^4.19.2"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@tachybase/
|
|
17
|
-
"@tachybase/
|
|
18
|
-
"@tachybase/
|
|
19
|
-
"@tachybase/
|
|
20
|
-
"@tachybase/
|
|
21
|
-
"@tachybase/
|
|
22
|
-
"@tachybase/
|
|
23
|
-
"@tachybase/test": "1.1.
|
|
24
|
-
"@tachybase/utils": "1.1.
|
|
16
|
+
"@tachybase/actions": "1.1.20",
|
|
17
|
+
"@tachybase/logger": "1.1.20",
|
|
18
|
+
"@tachybase/client": "1.1.20",
|
|
19
|
+
"@tachybase/module-collection": "1.1.20",
|
|
20
|
+
"@tachybase/schema": "1.1.20",
|
|
21
|
+
"@tachybase/module-user": "1.1.20",
|
|
22
|
+
"@tachybase/server": "1.1.20",
|
|
23
|
+
"@tachybase/test": "1.1.20",
|
|
24
|
+
"@tachybase/utils": "1.1.20"
|
|
25
25
|
},
|
|
26
26
|
"description.zh-CN": "工作线程,用于执行耗时任务",
|
|
27
27
|
"displayName.zh-CN": "工作线程",
|