verteilen-core 1.4.15 → 1.4.19
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/analysis.d.ts +17 -0
- package/dist/client/analysis.js +22 -0
- package/dist/client/client.d.ts +17 -0
- package/dist/client/client.js +33 -3
- package/dist/client/cluster.d.ts +3 -0
- package/dist/client/cluster.js +32 -0
- package/dist/client/database.d.ts +16 -0
- package/dist/client/database.js +16 -0
- package/dist/client/execute.d.ts +33 -0
- package/dist/client/execute.js +38 -0
- package/dist/client/javascript.d.ts +23 -0
- package/dist/client/javascript.js +34 -0
- package/dist/client/job_database.d.ts +4 -0
- package/dist/client/job_database.js +4 -0
- package/dist/client/job_execute.d.ts +28 -0
- package/dist/client/job_execute.js +29 -0
- package/dist/client/os.d.ts +26 -0
- package/dist/client/os.js +32 -0
- package/dist/client/resource.d.ts +3 -0
- package/dist/client/resource.js +8 -0
- package/dist/client/shell.d.ts +16 -0
- package/dist/client/shell.js +21 -0
- package/dist/computed.d.ts +13 -0
- package/dist/computed.js +14 -1
- package/dist/index.js +4 -0
- package/dist/interface/base.d.ts +261 -0
- package/dist/interface/base.js +8 -0
- package/dist/interface/bus.d.ts +73 -0
- package/dist/interface/enum.d.ts +67 -0
- package/dist/interface/enum.js +74 -0
- package/dist/interface/execute.d.ts +46 -0
- package/dist/interface/log.d.ts +54 -0
- package/dist/interface/plugin.d.ts +192 -0
- package/dist/interface/record.d.ts +13 -0
- package/dist/interface/server.d.ts +20 -0
- package/dist/interface/server.js +8 -0
- package/dist/interface/struct.d.ts +139 -0
- package/dist/interface/table.d.ts +39 -0
- package/dist/interface/ui.d.ts +104 -0
- package/dist/interface/ui.js +8 -0
- package/dist/interface.d.ts +30 -0
- package/dist/interface.js +35 -0
- package/dist/plugins/i18n.d.ts +19 -0
- package/dist/plugins/i18n.js +24 -0
- package/dist/script/console_manager.d.ts +3 -0
- package/dist/script/console_manager.js +3 -0
- package/dist/script/console_server_manager.d.ts +3 -0
- package/dist/script/console_server_manager.js +3 -0
- package/dist/script/execute/base.d.ts +96 -0
- package/dist/script/execute/base.js +105 -0
- package/dist/script/execute/feedback.d.ts +34 -0
- package/dist/script/execute/feedback.js +46 -0
- package/dist/script/execute/region_job.js +6 -0
- package/dist/script/execute/region_project.js +17 -0
- package/dist/script/execute/region_subtask.js +5 -0
- package/dist/script/execute/region_task.d.ts +37 -0
- package/dist/script/execute/region_task.js +75 -0
- package/dist/script/execute/runner.d.ts +7 -0
- package/dist/script/execute/runner.js +15 -0
- package/dist/script/execute/util_parser.d.ts +41 -0
- package/dist/script/execute/util_parser.js +47 -1
- package/dist/script/execute_manager.d.ts +38 -0
- package/dist/script/execute_manager.js +54 -0
- package/dist/script/socket_manager.d.ts +79 -0
- package/dist/script/socket_manager.js +84 -0
- package/dist/server/detail/console_handle.d.ts +13 -0
- package/dist/server/detail/console_handle.js +14 -0
- package/dist/server/detail/log_handle.d.ts +5 -0
- package/dist/server/detail/log_handle.js +5 -0
- package/dist/server/detail.d.ts +28 -0
- package/dist/server/detail.js +43 -0
- package/dist/server/io.d.ts +21 -0
- package/dist/server/io.js +18 -0
- package/dist/server/io2.d.ts +19 -0
- package/dist/server/io2.js +54 -0
- package/dist/server/module/account.d.ts +6 -0
- package/dist/server/module/account.js +11 -0
- package/dist/server/module/project.d.ts +49 -0
- package/dist/server/module/project.js +49 -0
- package/dist/server/plugin.d.ts +51 -0
- package/dist/server/plugin.js +13 -0
- package/dist/server/server.d.ts +21 -0
- package/dist/server/server.js +10 -0
- package/dist/server/server2.d.ts +4 -0
- package/dist/server/server2.js +9 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +3 -0
- package/dist/util/port.d.ts +1 -0
- package/dist/util/port.js +22 -0
- package/jest.config.ts +12 -0
- package/package.json +2 -1
- package/src/computed.ts +5 -1
- package/src/util/port.ts +15 -0
- package/test/call/print.ts +1 -1
- package/tsconfig.json +3 -4
- package/dist/server/observer.d.ts +0 -33
- package/dist/server/observer.js +0 -69
- package/jest.config.js +0 -8
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { WebSocket } from 'ws';
|
|
2
2
|
import { Header, Messager, Messager_log } from "../interface";
|
|
3
3
|
import { Client } from './client';
|
|
4
|
+
/**
|
|
5
|
+
* The analysis worker. decode the message received from cluster server
|
|
6
|
+
*/
|
|
4
7
|
export declare class ClientAnalysis {
|
|
5
8
|
private messager;
|
|
6
9
|
private messager_log;
|
|
@@ -11,12 +14,26 @@ export declare class ClientAnalysis {
|
|
|
11
14
|
private resource_thread;
|
|
12
15
|
private resource_cache;
|
|
13
16
|
constructor(_messager: Messager, _messager_log: Messager_log, _client: Client);
|
|
17
|
+
/**
|
|
18
|
+
* Analysis the package
|
|
19
|
+
* @param h Package
|
|
20
|
+
* @param source Websocket instance
|
|
21
|
+
* @return
|
|
22
|
+
* * 0: Successfully execute command
|
|
23
|
+
* * 1: The header is undefined, cannot process
|
|
24
|
+
* * 2: Cannot find the header name match with function typeMap
|
|
25
|
+
*/
|
|
14
26
|
analysis: (h: Header | undefined, source: WebSocket) => 0 | 1 | 2;
|
|
15
27
|
private execute_job;
|
|
16
28
|
private release;
|
|
17
29
|
private set_database;
|
|
18
30
|
private set_libs;
|
|
19
31
|
private exec_checker;
|
|
32
|
+
/**
|
|
33
|
+
* Network delay request
|
|
34
|
+
* @param data Dummy value, should always be 0
|
|
35
|
+
* @param source The cluster server websocket instance
|
|
36
|
+
*/
|
|
20
37
|
private pong;
|
|
21
38
|
private plugin_info;
|
|
22
39
|
private get_releases;
|
package/dist/client/analysis.js
CHANGED
|
@@ -34,6 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ClientAnalysis = void 0;
|
|
37
|
+
// ========================
|
|
38
|
+
//
|
|
39
|
+
// Share Codebase
|
|
40
|
+
//
|
|
41
|
+
// ========================
|
|
37
42
|
const child_process_1 = require("child_process");
|
|
38
43
|
const interface_1 = require("../interface");
|
|
39
44
|
const client_1 = require("./client");
|
|
@@ -42,6 +47,9 @@ const shell_1 = require("./shell");
|
|
|
42
47
|
const fs_1 = require("fs");
|
|
43
48
|
const path = __importStar(require("path"));
|
|
44
49
|
const os = __importStar(require("os"));
|
|
50
|
+
/**
|
|
51
|
+
* The analysis worker. decode the message received from cluster server
|
|
52
|
+
*/
|
|
45
53
|
class ClientAnalysis {
|
|
46
54
|
messager;
|
|
47
55
|
messager_log;
|
|
@@ -58,6 +66,15 @@ class ClientAnalysis {
|
|
|
58
66
|
this.shell = new shell_1.ClientShell(_messager, _messager_log, this.client);
|
|
59
67
|
this.exec = [];
|
|
60
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Analysis the package
|
|
71
|
+
* @param h Package
|
|
72
|
+
* @param source Websocket instance
|
|
73
|
+
* @return
|
|
74
|
+
* * 0: Successfully execute command
|
|
75
|
+
* * 1: The header is undefined, cannot process
|
|
76
|
+
* * 2: Cannot find the header name match with function typeMap
|
|
77
|
+
*/
|
|
61
78
|
analysis = (h, source) => {
|
|
62
79
|
const typeMap = {
|
|
63
80
|
'execute_job': this.execute_job,
|
|
@@ -135,6 +152,11 @@ class ClientAnalysis {
|
|
|
135
152
|
}
|
|
136
153
|
return r;
|
|
137
154
|
};
|
|
155
|
+
/**
|
|
156
|
+
* Network delay request
|
|
157
|
+
* @param data Dummy value, should always be 0
|
|
158
|
+
* @param source The cluster server websocket instance
|
|
159
|
+
*/
|
|
138
160
|
pong = (data, source) => {
|
|
139
161
|
const h = { name: 'pong', data: data };
|
|
140
162
|
source.send(JSON.stringify(h));
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { WebSocket } from 'ws';
|
|
2
2
|
import { Messager, Messager_log, PluginNode } from '../interface';
|
|
3
|
+
/**
|
|
4
|
+
* **Compute Client**\
|
|
5
|
+
* The calculation node worker
|
|
6
|
+
*/
|
|
3
7
|
export declare class Client {
|
|
4
8
|
plugins: PluginNode;
|
|
5
9
|
private httpss;
|
|
@@ -9,14 +13,27 @@ export declare class Client {
|
|
|
9
13
|
private messager_log;
|
|
10
14
|
private analysis;
|
|
11
15
|
private updatehandle;
|
|
16
|
+
/**
|
|
17
|
+
* Get connected client count
|
|
18
|
+
*/
|
|
12
19
|
get count(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Get connected client list instance
|
|
22
|
+
*/
|
|
13
23
|
get clients(): Array<WebSocket>;
|
|
14
24
|
constructor(_messager: Messager, _messager_log: Messager_log);
|
|
15
25
|
Dispose(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Start a websocket server, and waiting for cluster server to connect
|
|
28
|
+
*/
|
|
16
29
|
Init: () => Promise<void>;
|
|
17
30
|
Destroy: () => void;
|
|
18
31
|
Release: () => void;
|
|
19
32
|
savePlugin: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* The node update function, It will do things below
|
|
35
|
+
* * Send system info to cluster server
|
|
36
|
+
*/
|
|
20
37
|
private update;
|
|
21
38
|
private loadPlugins;
|
|
22
39
|
private get_pem;
|
package/dist/client/client.js
CHANGED
|
@@ -34,6 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Client = void 0;
|
|
37
|
+
// ========================
|
|
38
|
+
//
|
|
39
|
+
// Share Codebase
|
|
40
|
+
//
|
|
41
|
+
// ========================
|
|
37
42
|
const path = __importStar(require("path"));
|
|
38
43
|
const tcp_port_used_1 = require("tcp-port-used");
|
|
39
44
|
const ws = __importStar(require("ws"));
|
|
@@ -43,6 +48,10 @@ const fs_1 = require("fs");
|
|
|
43
48
|
const os = __importStar(require("os"));
|
|
44
49
|
const pem = __importStar(require("pem"));
|
|
45
50
|
const https = __importStar(require("https"));
|
|
51
|
+
/**
|
|
52
|
+
* **Compute Client**\
|
|
53
|
+
* The calculation node worker
|
|
54
|
+
*/
|
|
46
55
|
class Client {
|
|
47
56
|
plugins = { plugins: [] };
|
|
48
57
|
httpss = undefined;
|
|
@@ -52,9 +61,15 @@ class Client {
|
|
|
52
61
|
messager_log;
|
|
53
62
|
analysis;
|
|
54
63
|
updatehandle;
|
|
64
|
+
/**
|
|
65
|
+
* Get connected client count
|
|
66
|
+
*/
|
|
55
67
|
get count() {
|
|
56
68
|
return this.sources.length;
|
|
57
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Get connected client list instance
|
|
72
|
+
*/
|
|
58
73
|
get clients() {
|
|
59
74
|
return this.sources;
|
|
60
75
|
}
|
|
@@ -68,6 +83,9 @@ class Client {
|
|
|
68
83
|
Dispose() {
|
|
69
84
|
clearInterval(this.updatehandle);
|
|
70
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Start a websocket server, and waiting for cluster server to connect
|
|
88
|
+
*/
|
|
71
89
|
Init = async () => {
|
|
72
90
|
let port_result = interface_1.PORT;
|
|
73
91
|
let canbeuse = false;
|
|
@@ -144,6 +162,10 @@ class Client {
|
|
|
144
162
|
(0, fs_1.mkdirSync)(f, { recursive: true });
|
|
145
163
|
(0, fs_1.writeFileSync)(pluginPath, JSON.stringify(this.plugins, null, 4));
|
|
146
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* The node update function, It will do things below
|
|
167
|
+
* * Send system info to cluster server
|
|
168
|
+
*/
|
|
147
169
|
update = () => {
|
|
148
170
|
this.analysis.forEach(x => x.update(this));
|
|
149
171
|
};
|
|
@@ -179,16 +201,17 @@ class Client {
|
|
|
179
201
|
});
|
|
180
202
|
};
|
|
181
203
|
static workerPath = (filename = "worker", extension = ".exe") => {
|
|
204
|
+
// @ts-ignore
|
|
182
205
|
const isExe = process.pkg?.entrypoint != undefined;
|
|
183
206
|
const exe = process.platform == 'win32' ? filename + extension : filename;
|
|
184
207
|
let workerExe = "";
|
|
185
208
|
let p = 0;
|
|
186
|
-
if (isExe && path.basename(process.execPath) == (process.platform ? "app.exe" : 'app')) {
|
|
209
|
+
if (isExe && path.basename(process.execPath) == (process.platform ? "app.exe" : 'app')) { // Node build
|
|
187
210
|
workerExe = path.join(process.execPath, "..", "bin", exe);
|
|
188
211
|
p = 1;
|
|
189
212
|
}
|
|
190
213
|
else if ((process.mainModule && process.mainModule.filename.indexOf('app.asar') !== -1) ||
|
|
191
|
-
process.argv.filter(a => a.indexOf('app.asar') !== -1).length > 0) {
|
|
214
|
+
process.argv.filter(a => a.indexOf('app.asar') !== -1).length > 0) { // Electron package
|
|
192
215
|
workerExe = path.join("bin", exe);
|
|
193
216
|
p = 2;
|
|
194
217
|
}
|
|
@@ -196,22 +219,29 @@ class Client {
|
|
|
196
219
|
workerExe = path.join(process.cwd(), "bin", exe);
|
|
197
220
|
p = 3;
|
|
198
221
|
}
|
|
199
|
-
else {
|
|
222
|
+
else { // Node un-build
|
|
200
223
|
workerExe = Client.isTypescript() ? path.join(__dirname, "bin", exe) : path.join(__dirname, "..", "bin", exe);
|
|
201
224
|
p = 4;
|
|
202
225
|
}
|
|
203
226
|
return workerExe;
|
|
204
227
|
};
|
|
205
228
|
static isTypescript = () => {
|
|
229
|
+
// if this file is typescript, we are running typescript :D
|
|
230
|
+
// this is the best check, but fails when actionhero is compiled to js though...
|
|
206
231
|
const extension = path.extname(__filename);
|
|
207
232
|
if (extension === ".ts") {
|
|
208
233
|
return true;
|
|
209
234
|
}
|
|
235
|
+
// are we running via a ts-node/ts-node-dev shim?
|
|
210
236
|
const lastArg = process.execArgv[process.execArgv.length - 1];
|
|
211
237
|
if (lastArg && path.parse(lastArg).name.indexOf("ts-node") > 0) {
|
|
212
238
|
return true;
|
|
213
239
|
}
|
|
214
240
|
try {
|
|
241
|
+
/**
|
|
242
|
+
* Are we running in typescript at the moment?
|
|
243
|
+
* see https://github.com/TypeStrong/ts-node/pull/858 for more details
|
|
244
|
+
*/
|
|
215
245
|
return process[Symbol.for("ts-node.register.instance")] ||
|
|
216
246
|
(process.env.NODE_ENV === "test" &&
|
|
217
247
|
process.env.ACTIONHERO_TEST_FILE_EXTENSION !== "js")
|
package/dist/client/cluster.d.ts
CHANGED
package/dist/client/cluster.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RUN = RUN;
|
|
4
|
+
// ========================
|
|
5
|
+
//
|
|
6
|
+
// Share Codebase
|
|
7
|
+
//
|
|
8
|
+
// ========================
|
|
4
9
|
const interface_1 = require("../interface");
|
|
5
10
|
const http_1 = require("./http");
|
|
6
11
|
const job_execute_1 = require("./job_execute");
|
|
@@ -16,6 +21,11 @@ process.stdin.on('data', (chunk) => {
|
|
|
16
21
|
setTimeout(process.exit(1), 1000);
|
|
17
22
|
}
|
|
18
23
|
});
|
|
24
|
+
/**
|
|
25
|
+
* The message handle for reply
|
|
26
|
+
* @param msg Message
|
|
27
|
+
* @param tag Message prefix
|
|
28
|
+
*/
|
|
19
29
|
const messager = (msg, tag) => {
|
|
20
30
|
const d = {
|
|
21
31
|
name: 'messager',
|
|
@@ -24,6 +34,11 @@ const messager = (msg, tag) => {
|
|
|
24
34
|
};
|
|
25
35
|
console.log(JSON.stringify(d));
|
|
26
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* The message handle for reply with print on screen ffeature
|
|
39
|
+
* @param msg Message
|
|
40
|
+
* @param tag Message prefix
|
|
41
|
+
*/
|
|
27
42
|
const messager_log = (msg, tag, meta) => {
|
|
28
43
|
const d = {
|
|
29
44
|
name: 'messager_log',
|
|
@@ -32,6 +47,10 @@ const messager_log = (msg, tag, meta) => {
|
|
|
32
47
|
};
|
|
33
48
|
console.log(JSON.stringify(d));
|
|
34
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Return the error message to main thread
|
|
52
|
+
* @param err Error instance
|
|
53
|
+
*/
|
|
35
54
|
const ERROR = (err) => {
|
|
36
55
|
const d = {
|
|
37
56
|
name: "error",
|
|
@@ -41,6 +60,9 @@ const ERROR = (err) => {
|
|
|
41
60
|
console.log(JSON.stringify(d));
|
|
42
61
|
process.exit(1);
|
|
43
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Job execute task
|
|
65
|
+
*/
|
|
44
66
|
const execute_job = () => {
|
|
45
67
|
if (process.env.job == undefined || process.env.plugin == undefined) {
|
|
46
68
|
process.exit(1);
|
|
@@ -54,6 +76,9 @@ const execute_job = () => {
|
|
|
54
76
|
})
|
|
55
77
|
.catch(err => ERROR(err));
|
|
56
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Query resource task
|
|
81
|
+
*/
|
|
57
82
|
const execute_resource = () => {
|
|
58
83
|
const r = new resource_1.ClientResource();
|
|
59
84
|
messager("Resource query");
|
|
@@ -67,6 +92,9 @@ const execute_resource = () => {
|
|
|
67
92
|
console.log(JSON.stringify(h));
|
|
68
93
|
}).catch(err => ERROR(err));
|
|
69
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Query http task
|
|
97
|
+
*/
|
|
70
98
|
const execute_http = () => {
|
|
71
99
|
const m = process.env.method || 'GET';
|
|
72
100
|
const u = process.env.url || '';
|
|
@@ -74,7 +102,11 @@ const execute_http = () => {
|
|
|
74
102
|
const r = new http_1.ClientHTTP(u, m, p);
|
|
75
103
|
r.RUN();
|
|
76
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* The entry point for the cluster thread.
|
|
107
|
+
*/
|
|
77
108
|
function RUN() {
|
|
109
|
+
// The cluster currently spawn should execute a job
|
|
78
110
|
switch (process.env.type) {
|
|
79
111
|
case 'JOB':
|
|
80
112
|
execute_job();
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
2
|
import { Setter } from "../interface";
|
|
3
|
+
/**
|
|
4
|
+
* The database feedback helper\
|
|
5
|
+
* Update the main database container on the cluster server
|
|
6
|
+
*/
|
|
3
7
|
export declare class ClientDatabase {
|
|
4
8
|
private source;
|
|
5
9
|
constructor(_source: WebSocket | undefined);
|
|
10
|
+
/**
|
|
11
|
+
* Update database number on the cluster server
|
|
12
|
+
* @param data Target KeyValue
|
|
13
|
+
*/
|
|
6
14
|
feedbacknumber: (data: Setter) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Update database boolean on the cluster server
|
|
17
|
+
* @param data Target KeyValue
|
|
18
|
+
*/
|
|
7
19
|
feedbackboolean: (data: Setter) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Update database string on the cluster server
|
|
22
|
+
* @param data Target KeyValue
|
|
23
|
+
*/
|
|
8
24
|
feedbackstring: (data: Setter) => void;
|
|
9
25
|
feedbackobject: (data: Setter) => void;
|
|
10
26
|
feedbacklist: (data: Setter) => void;
|
package/dist/client/database.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClientDatabase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The database feedback helper\
|
|
6
|
+
* Update the main database container on the cluster server
|
|
7
|
+
*/
|
|
4
8
|
class ClientDatabase {
|
|
5
9
|
source;
|
|
6
10
|
constructor(_source) {
|
|
7
11
|
this.source = _source;
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Update database number on the cluster server
|
|
15
|
+
* @param data Target KeyValue
|
|
16
|
+
*/
|
|
9
17
|
feedbacknumber = (data) => {
|
|
10
18
|
this.feedback("feedback_number", data);
|
|
11
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Update database boolean on the cluster server
|
|
22
|
+
* @param data Target KeyValue
|
|
23
|
+
*/
|
|
12
24
|
feedbackboolean = (data) => {
|
|
13
25
|
this.feedback("feedback_boolean", data);
|
|
14
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Update database string on the cluster server
|
|
29
|
+
* @param data Target KeyValue
|
|
30
|
+
*/
|
|
15
31
|
feedbackstring = (data) => {
|
|
16
32
|
this.feedback("feedback_string", data);
|
|
17
33
|
};
|
package/dist/client/execute.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { WebSocket } from 'ws';
|
|
2
2
|
import { Job, Libraries, Messager, Messager_log, Database, Setter } from "../interface";
|
|
3
3
|
import { Client } from "./client";
|
|
4
|
+
/**
|
|
5
|
+
* Execute worker, Execute the job container
|
|
6
|
+
*/
|
|
4
7
|
export declare class ClientExecute {
|
|
5
8
|
uuid: string;
|
|
6
9
|
private database;
|
|
@@ -12,13 +15,43 @@ export declare class ClientExecute {
|
|
|
12
15
|
private messager_log;
|
|
13
16
|
get count(): number;
|
|
14
17
|
constructor(_uuid: string, _messager: Messager, _messager_log: Messager_log, _client: Client);
|
|
18
|
+
/**
|
|
19
|
+
* The stop signal, It will trying to kill the process if currently running
|
|
20
|
+
*/
|
|
15
21
|
stop_job: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* The entry function to execute the job container
|
|
24
|
+
* @param job Target job
|
|
25
|
+
*/
|
|
16
26
|
execute_job: (job: Job, source: WebSocket) => void;
|
|
17
27
|
private execute_job_worker;
|
|
18
28
|
private job_finish;
|
|
29
|
+
/**
|
|
30
|
+
* Update database, Called by cluster server
|
|
31
|
+
* @param data Target container
|
|
32
|
+
*/
|
|
19
33
|
set_database: (data: Database) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Update libraries, Called by cluster server
|
|
36
|
+
* @param data Target container
|
|
37
|
+
*/
|
|
20
38
|
set_libs: (data: Libraries) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Update database string, Called by cluster server
|
|
41
|
+
* @deprecated The method should not be used
|
|
42
|
+
* @param data Target keyvalue
|
|
43
|
+
*/
|
|
21
44
|
set_string: (data: Setter) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Update database number, Called by cluster server
|
|
47
|
+
* @deprecated The method should not be used
|
|
48
|
+
* @param data Target keyvalue
|
|
49
|
+
*/
|
|
22
50
|
set_number: (data: Setter) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Update database boolean, Called by cluster server
|
|
53
|
+
* @deprecated The method should not be used
|
|
54
|
+
* @param data Target keyvalue
|
|
55
|
+
*/
|
|
23
56
|
set_boolean: (data: Setter) => void;
|
|
24
57
|
}
|
package/dist/client/execute.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClientExecute = void 0;
|
|
4
|
+
// ========================
|
|
5
|
+
//
|
|
6
|
+
// Share Codebase
|
|
7
|
+
//
|
|
8
|
+
// ========================
|
|
4
9
|
const child_process_1 = require("child_process");
|
|
5
10
|
const ws_1 = require("ws");
|
|
6
11
|
const interface_1 = require("../interface");
|
|
7
12
|
const i18n_1 = require("../plugins/i18n");
|
|
8
13
|
const client_1 = require("./client");
|
|
9
14
|
const database_1 = require("./database");
|
|
15
|
+
/**
|
|
16
|
+
* Execute worker, Execute the job container
|
|
17
|
+
*/
|
|
10
18
|
class ClientExecute {
|
|
11
19
|
uuid;
|
|
12
20
|
database = undefined;
|
|
@@ -25,6 +33,9 @@ class ClientExecute {
|
|
|
25
33
|
this.messager = _messager;
|
|
26
34
|
this.messager_log = _messager_log;
|
|
27
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* The stop signal, It will trying to kill the process if currently running
|
|
38
|
+
*/
|
|
28
39
|
stop_job = () => {
|
|
29
40
|
this.messager_log(`[Execute] Stop All: ${this.workers.length}`);
|
|
30
41
|
this.workers.forEach(x => {
|
|
@@ -34,6 +45,10 @@ class ClientExecute {
|
|
|
34
45
|
x.stdin.end();
|
|
35
46
|
});
|
|
36
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* The entry function to execute the job container
|
|
50
|
+
* @param job Target job
|
|
51
|
+
*/
|
|
37
52
|
execute_job = (job, source) => {
|
|
38
53
|
this.messager_log(`[Execute] ${job.uuid} ${job.category == interface_1.JobCategory.Execution ? i18n_1.i18n.global.t(interface_1.JobTypeText[job.type]) : i18n_1.i18n.global.t(interface_1.JobType2Text[job.type])}`, job.uuid, job.runtime_uuid);
|
|
39
54
|
this.tag = job.uuid;
|
|
@@ -138,12 +153,25 @@ class ClientExecute {
|
|
|
138
153
|
}
|
|
139
154
|
this.tag = '';
|
|
140
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Update database, Called by cluster server
|
|
158
|
+
* @param data Target container
|
|
159
|
+
*/
|
|
141
160
|
set_database = (data) => {
|
|
142
161
|
this.database = data;
|
|
143
162
|
};
|
|
163
|
+
/**
|
|
164
|
+
* Update libraries, Called by cluster server
|
|
165
|
+
* @param data Target container
|
|
166
|
+
*/
|
|
144
167
|
set_libs = (data) => {
|
|
145
168
|
this.libraries = data;
|
|
146
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* Update database string, Called by cluster server
|
|
172
|
+
* @deprecated The method should not be used
|
|
173
|
+
* @param data Target keyvalue
|
|
174
|
+
*/
|
|
147
175
|
set_string = (data) => {
|
|
148
176
|
if (this.database == undefined)
|
|
149
177
|
return;
|
|
@@ -152,6 +180,11 @@ class ClientExecute {
|
|
|
152
180
|
this.database.containers[index].value = data.value;
|
|
153
181
|
this.messager_log(`[Database string sync] ${data.key} = ${data.value}`);
|
|
154
182
|
};
|
|
183
|
+
/**
|
|
184
|
+
* Update database number, Called by cluster server
|
|
185
|
+
* @deprecated The method should not be used
|
|
186
|
+
* @param data Target keyvalue
|
|
187
|
+
*/
|
|
155
188
|
set_number = (data) => {
|
|
156
189
|
if (this.database == undefined)
|
|
157
190
|
return;
|
|
@@ -160,6 +193,11 @@ class ClientExecute {
|
|
|
160
193
|
this.database.containers[index].value = data.value;
|
|
161
194
|
this.messager_log(`[Database number sync] ${data.key} = ${data.value}`);
|
|
162
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* Update database boolean, Called by cluster server
|
|
198
|
+
* @deprecated The method should not be used
|
|
199
|
+
* @param data Target keyvalue
|
|
200
|
+
*/
|
|
163
201
|
set_boolean = (data) => {
|
|
164
202
|
if (this.database == undefined)
|
|
165
203
|
return;
|
|
@@ -13,8 +13,31 @@ export declare class ClientJavascript {
|
|
|
13
13
|
message: any;
|
|
14
14
|
http: any;
|
|
15
15
|
constructor(_messager: Messager, _messager_log: Messager_log, _getjob: Getjob);
|
|
16
|
+
/**
|
|
17
|
+
* Before running the js scripts, We must init first.\
|
|
18
|
+
* ! Otherwise it won't work or throw error
|
|
19
|
+
* @param _messager Message habndle
|
|
20
|
+
* @param _messager_log Message habndle with print on screen feature
|
|
21
|
+
* @param _clientos OS worker
|
|
22
|
+
* @param _para Database worker
|
|
23
|
+
* @param _getlib library getter method
|
|
24
|
+
* @param _getpara Database getter method
|
|
25
|
+
* @param _getjob Job getter method
|
|
26
|
+
*/
|
|
16
27
|
static Init: (_messager: Messager, _messager_log: Messager, _clientos: ClientOS, _para: ClientJobDatabase, _getlib: Getlib, _getpara: Getpara, _getjob: Getjob) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Running js\
|
|
30
|
+
* With reference libraries\
|
|
31
|
+
* @param js js script text
|
|
32
|
+
* @param libs Libraries header names
|
|
33
|
+
* @returns Calcuate result
|
|
34
|
+
*/
|
|
17
35
|
JavascriptExecuteWithLib: (javascript: string, libs: Array<string>, log?: Messager) => Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* Running js
|
|
38
|
+
* @param js js script text
|
|
39
|
+
* @returns Calcuate result
|
|
40
|
+
*/
|
|
18
41
|
JavascriptExecute: (javascript: string, log?: Messager) => Promise<any>;
|
|
19
42
|
private getJavascriptEnv;
|
|
20
43
|
private filename;
|
|
@@ -34,6 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ClientJavascript = exports.safeEval = void 0;
|
|
37
|
+
// ========================
|
|
38
|
+
//
|
|
39
|
+
// Share Codebase
|
|
40
|
+
//
|
|
41
|
+
// ========================
|
|
37
42
|
const vm = __importStar(require("vm"));
|
|
38
43
|
const interface_1 = require("../interface");
|
|
39
44
|
const path = __importStar(require("path"));
|
|
@@ -73,6 +78,7 @@ let para = undefined;
|
|
|
73
78
|
let waiting = 0;
|
|
74
79
|
const tag = () => getjob?.()?.uuid ?? 'unknown';
|
|
75
80
|
const runtime = () => getjob?.()?.runtime_uuid ?? 'unknown';
|
|
81
|
+
//#region Global
|
|
76
82
|
function has(key, checker) {
|
|
77
83
|
const p = getpara?.() ?? undefined;
|
|
78
84
|
if (p == undefined)
|
|
@@ -231,6 +237,7 @@ function setselect(key, value) {
|
|
|
231
237
|
target.value = value;
|
|
232
238
|
para?.feedbackobject({ key: key, value: value });
|
|
233
239
|
}
|
|
240
|
+
//#endregion
|
|
234
241
|
class ClientJavascript {
|
|
235
242
|
path;
|
|
236
243
|
os;
|
|
@@ -298,6 +305,17 @@ class ClientJavascript {
|
|
|
298
305
|
patch: this.httpPatch,
|
|
299
306
|
};
|
|
300
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Before running the js scripts, We must init first.\
|
|
310
|
+
* ! Otherwise it won't work or throw error
|
|
311
|
+
* @param _messager Message habndle
|
|
312
|
+
* @param _messager_log Message habndle with print on screen feature
|
|
313
|
+
* @param _clientos OS worker
|
|
314
|
+
* @param _para Database worker
|
|
315
|
+
* @param _getlib library getter method
|
|
316
|
+
* @param _getpara Database getter method
|
|
317
|
+
* @param _getjob Job getter method
|
|
318
|
+
*/
|
|
301
319
|
static Init = (_messager, _messager_log, _clientos, _para, _getlib, _getpara, _getjob) => {
|
|
302
320
|
messager = _messager;
|
|
303
321
|
messager_log = _messager_log;
|
|
@@ -307,6 +325,13 @@ class ClientJavascript {
|
|
|
307
325
|
getpara = _getpara;
|
|
308
326
|
getjob = _getjob;
|
|
309
327
|
};
|
|
328
|
+
/**
|
|
329
|
+
* Running js\
|
|
330
|
+
* With reference libraries\
|
|
331
|
+
* @param js js script text
|
|
332
|
+
* @param libs Libraries header names
|
|
333
|
+
* @returns Calcuate result
|
|
334
|
+
*/
|
|
310
335
|
JavascriptExecuteWithLib = (javascript, libs, log) => {
|
|
311
336
|
waiting = 0;
|
|
312
337
|
let context = this.getJavascriptEnv(interface_1.JavascriptLib.ALL, log);
|
|
@@ -335,6 +360,11 @@ class ClientJavascript {
|
|
|
335
360
|
}, 100);
|
|
336
361
|
});
|
|
337
362
|
};
|
|
363
|
+
/**
|
|
364
|
+
* Running js
|
|
365
|
+
* @param js js script text
|
|
366
|
+
* @returns Calcuate result
|
|
367
|
+
*/
|
|
338
368
|
JavascriptExecute = (javascript, log) => {
|
|
339
369
|
waiting = 0;
|
|
340
370
|
let context = this.getJavascriptEnv(interface_1.JavascriptLib.OS | interface_1.JavascriptLib.MESSAGE | interface_1.JavascriptLib.HTTP | interface_1.JavascriptLib.PATH, log);
|
|
@@ -497,12 +527,16 @@ class ClientJavascript {
|
|
|
497
527
|
readfile(path) {
|
|
498
528
|
return clientos?.file_read({ path: path });
|
|
499
529
|
}
|
|
530
|
+
//#region Databases
|
|
500
531
|
async wait(time) {
|
|
501
532
|
return new Promise((resolve) => setTimeout(resolve, time * 1000));
|
|
502
533
|
}
|
|
503
534
|
async sleep(n) {
|
|
504
535
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n * 1000);
|
|
505
536
|
}
|
|
537
|
+
//#endregion
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region Http
|
|
506
540
|
async httpGet(url, p) {
|
|
507
541
|
return this.httpGo('GET', url, p.toObject());
|
|
508
542
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Setter } from "../interface";
|
|
2
2
|
export declare class ClientJobDatabase {
|
|
3
|
+
/**
|
|
4
|
+
* Update database number on the cluster server
|
|
5
|
+
* @param data Target KeyValue
|
|
6
|
+
*/
|
|
3
7
|
feedbacknumber: (data: Setter) => void;
|
|
4
8
|
feedbackboolean: (data: Setter) => void;
|
|
5
9
|
feedbackstring: (data: Setter) => void;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClientJobDatabase = void 0;
|
|
4
4
|
class ClientJobDatabase {
|
|
5
|
+
/**
|
|
6
|
+
* Update database number on the cluster server
|
|
7
|
+
* @param data Target KeyValue
|
|
8
|
+
*/
|
|
5
9
|
feedbacknumber = (data) => {
|
|
6
10
|
this.feedback("feedbacknumber", data);
|
|
7
11
|
};
|