verteilen-core 1.4.17 → 1.4.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/client/analysis.js +26 -63
- package/dist/client/client.js +31 -68
- package/dist/client/cluster.js +9 -12
- package/dist/client/database.js +1 -5
- package/dist/client/execute.js +14 -18
- package/dist/client/http.js +1 -5
- package/dist/client/javascript.js +49 -87
- package/dist/client/job_database.js +1 -5
- package/dist/client/job_execute.js +24 -28
- package/dist/client/os.js +11 -51
- package/dist/client/resource.js +13 -20
- package/dist/client/shell.js +5 -9
- package/dist/computed.js +17 -53
- package/dist/index.js +4 -20
- package/dist/interface/base.js +12 -19
- package/dist/interface/bus.js +1 -2
- package/dist/interface/enum.js +43 -46
- package/dist/interface/execute.js +1 -2
- package/dist/interface/log.js +1 -2
- package/dist/interface/plugin.js +1 -2
- package/dist/interface/record.js +1 -5
- package/dist/interface/server.js +13 -19
- package/dist/interface/struct.js +1 -2
- package/dist/interface/table.js +1 -2
- package/dist/interface/ui.js +1 -2
- package/dist/interface.js +33 -72
- package/dist/plugins/i18n.js +12 -18
- package/dist/script/console_manager.js +1 -5
- package/dist/script/console_server_manager.js +1 -5
- package/dist/script/execute/base.d.ts +2 -2
- package/dist/script/execute/base.js +17 -21
- package/dist/script/execute/feedback.js +16 -20
- package/dist/script/execute/index.js +8 -24
- package/dist/script/execute/region_job.js +6 -10
- package/dist/script/execute/region_project.js +8 -12
- package/dist/script/execute/region_subtask.js +7 -11
- package/dist/script/execute/region_task.d.ts +4 -5
- package/dist/script/execute/region_task.js +25 -29
- package/dist/script/execute/runner.js +6 -10
- package/dist/script/execute/util_parser.js +13 -17
- package/dist/script/execute_manager.js +37 -41
- package/dist/script/socket_manager.js +14 -51
- package/dist/script/webhook_manager.js +1 -5
- package/dist/script/webhook_server_manager.js +18 -55
- package/dist/server/detail/console_handle.js +26 -31
- package/dist/server/detail/log_handle.js +18 -55
- package/dist/server/detail.d.ts +4 -4
- package/dist/server/detail.js +25 -29
- package/dist/server/io.js +18 -22
- package/dist/server/io2.js +53 -62
- package/dist/server/module/account.js +4 -11
- package/dist/server/module/index.js +3 -19
- package/dist/server/module/log.js +1 -5
- package/dist/server/module/project.d.ts +1 -1
- package/dist/server/module/project.js +5 -9
- package/dist/server/module/service.js +1 -5
- package/dist/server/plugin.js +4 -9
- package/dist/server/server.js +5 -9
- package/dist/server/server2.js +2 -6
- package/dist/server.js +5 -21
- package/dist/util/plugin_builder.js +5 -42
- package/dist/util/port.js +3 -10
- package/dist/utility.js +1 -17
- package/jest.config.ts +12 -0
- package/package.json +1 -1
- package/test/call/print.ts +1 -1
- package/tsconfig.json +3 -2
- package/dist/server/observer.d.ts +0 -33
- package/dist/server/observer.js +0 -69
- package/jest.config.js +0 -8
package/dist/client/analysis.js
CHANGED
|
@@ -1,56 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ClientAnalysis = void 0;
|
|
37
1
|
// ========================
|
|
38
2
|
//
|
|
39
3
|
// Share Codebase
|
|
40
4
|
//
|
|
41
5
|
// ========================
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
6
|
+
import { exec, spawn } from 'child_process';
|
|
7
|
+
import { DATA_FOLDER } from "../interface";
|
|
8
|
+
import { Client } from './client';
|
|
9
|
+
import { ClientExecute } from "./execute";
|
|
10
|
+
import { ClientShell } from './shell';
|
|
11
|
+
import { createWriteStream, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import * as os from 'os';
|
|
50
14
|
/**
|
|
51
15
|
* The analysis worker. decode the message received from cluster server
|
|
52
16
|
*/
|
|
53
|
-
class ClientAnalysis {
|
|
17
|
+
export class ClientAnalysis {
|
|
54
18
|
messager;
|
|
55
19
|
messager_log;
|
|
56
20
|
client;
|
|
@@ -63,7 +27,7 @@ class ClientAnalysis {
|
|
|
63
27
|
this.client = _client;
|
|
64
28
|
this.messager = _messager;
|
|
65
29
|
this.messager_log = _messager_log;
|
|
66
|
-
this.shell = new
|
|
30
|
+
this.shell = new ClientShell(_messager, _messager_log, this.client);
|
|
67
31
|
this.exec = [];
|
|
68
32
|
}
|
|
69
33
|
/**
|
|
@@ -144,7 +108,7 @@ class ClientAnalysis {
|
|
|
144
108
|
let r = undefined;
|
|
145
109
|
const index = this.exec.findIndex(x => x.uuid == uuid);
|
|
146
110
|
if (index == -1) {
|
|
147
|
-
r = new
|
|
111
|
+
r = new ClientExecute(uuid, this.messager, this.messager_log, this.client);
|
|
148
112
|
this.exec.push(r);
|
|
149
113
|
}
|
|
150
114
|
else {
|
|
@@ -162,16 +126,16 @@ class ClientAnalysis {
|
|
|
162
126
|
source.send(JSON.stringify(h));
|
|
163
127
|
};
|
|
164
128
|
plugin_info = (data, source) => {
|
|
165
|
-
const pat = path.join(os.homedir(),
|
|
166
|
-
if (
|
|
167
|
-
const p = JSON.parse(
|
|
129
|
+
const pat = path.join(os.homedir(), DATA_FOLDER, "node_plugin", "plugin.json");
|
|
130
|
+
if (existsSync(pat)) {
|
|
131
|
+
const p = JSON.parse(readFileSync(pat).toString());
|
|
168
132
|
const h = { name: 'plugin_info_reply', data: p.plugins };
|
|
169
133
|
source.send(JSON.stringify(h));
|
|
170
134
|
}
|
|
171
135
|
else {
|
|
172
136
|
const p = { plugins: [] };
|
|
173
137
|
const h = { name: 'plugin_info_reply', data: p.plugins };
|
|
174
|
-
|
|
138
|
+
writeFileSync(pat, JSON.stringify(p));
|
|
175
139
|
source.send(JSON.stringify(h));
|
|
176
140
|
}
|
|
177
141
|
};
|
|
@@ -232,12 +196,12 @@ class ClientAnalysis {
|
|
|
232
196
|
const filename = links[links.length - 1];
|
|
233
197
|
const version = links[links.length - 2];
|
|
234
198
|
const REPO = `${links[3]}/${links[4]}`;
|
|
235
|
-
const dir = path.join(os.homedir(),
|
|
236
|
-
if (!
|
|
237
|
-
|
|
199
|
+
const dir = path.join(os.homedir(), DATA_FOLDER, "node_plugin", plugin.name);
|
|
200
|
+
if (!existsSync(dir))
|
|
201
|
+
mkdirSync(dir, { recursive: true });
|
|
238
202
|
let req = {};
|
|
239
203
|
const tokens = [undefined, ...plugin.token];
|
|
240
|
-
const fileStream =
|
|
204
|
+
const fileStream = createWriteStream(path.join(dir, target.filename), { flags: 'a' });
|
|
241
205
|
let pass = false;
|
|
242
206
|
for (let t of tokens) {
|
|
243
207
|
if (pass)
|
|
@@ -270,7 +234,7 @@ class ClientAnalysis {
|
|
|
270
234
|
this.messager_log(`[Plugin] Downloaded ${plugin.name} successfully`);
|
|
271
235
|
fileStream.end();
|
|
272
236
|
if (process.platform == 'linux') {
|
|
273
|
-
|
|
237
|
+
exec(`chmod +x ${path.join(dir, target.filename)}`, (err) => {
|
|
274
238
|
this.messager_log(`[Plugin] Permission failed ${err?.message}`);
|
|
275
239
|
});
|
|
276
240
|
}
|
|
@@ -286,11 +250,11 @@ class ClientAnalysis {
|
|
|
286
250
|
plugin_remove = (plugin, source) => {
|
|
287
251
|
this.client.plugins.plugins = this.client.plugins.plugins.filter(x => x.name != plugin.name);
|
|
288
252
|
this.client.savePlugin();
|
|
289
|
-
const dir = path.join(os.homedir(),
|
|
290
|
-
if (!
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
|
|
253
|
+
const dir = path.join(os.homedir(), DATA_FOLDER, "node_plugin");
|
|
254
|
+
if (!existsSync(dir))
|
|
255
|
+
mkdirSync(dir, { recursive: true });
|
|
256
|
+
if (existsSync(path.join(dir, plugin.name))) {
|
|
257
|
+
rmSync(path.join(dir, plugin.name), { recursive: true });
|
|
294
258
|
}
|
|
295
259
|
this.plugin_info(0, source);
|
|
296
260
|
};
|
|
@@ -330,7 +294,7 @@ class ClientAnalysis {
|
|
|
330
294
|
const shouldRun = this.resource_thread == undefined && (this.resource_cache == undefined || this.resource_wanter.length > 0);
|
|
331
295
|
if (!shouldRun)
|
|
332
296
|
return;
|
|
333
|
-
this.resource_thread =
|
|
297
|
+
this.resource_thread = spawn(Client.workerPath(), [], {
|
|
334
298
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
335
299
|
shell: true,
|
|
336
300
|
windowsHide: true,
|
|
@@ -399,4 +363,3 @@ class ClientAnalysis {
|
|
|
399
363
|
});
|
|
400
364
|
};
|
|
401
365
|
}
|
|
402
|
-
exports.ClientAnalysis = ClientAnalysis;
|
package/dist/client/client.js
CHANGED
|
@@ -1,58 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Client = void 0;
|
|
37
1
|
// ========================
|
|
38
2
|
//
|
|
39
3
|
// Share Codebase
|
|
40
4
|
//
|
|
41
5
|
// ========================
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { check } from 'tcp-port-used';
|
|
8
|
+
import * as ws from 'ws';
|
|
9
|
+
import { CLIENT_UPDATETICK, DATA_FOLDER, PORT } from '../interface';
|
|
10
|
+
import { ClientAnalysis } from './analysis';
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
12
|
+
import * as os from 'os';
|
|
13
|
+
import * as pem from 'pem';
|
|
14
|
+
import * as https from 'https';
|
|
51
15
|
/**
|
|
52
16
|
* **Compute Client**\
|
|
53
17
|
* The calculation node worker
|
|
54
18
|
*/
|
|
55
|
-
class Client {
|
|
19
|
+
export class Client {
|
|
56
20
|
plugins = { plugins: [] };
|
|
57
21
|
httpss = undefined;
|
|
58
22
|
client = undefined;
|
|
@@ -77,7 +41,7 @@ class Client {
|
|
|
77
41
|
this.messager = _messager;
|
|
78
42
|
this.messager_log = _messager_log;
|
|
79
43
|
this.analysis = [];
|
|
80
|
-
this.updatehandle = setInterval(this.update,
|
|
44
|
+
this.updatehandle = setInterval(this.update, CLIENT_UPDATETICK);
|
|
81
45
|
this.loadPlugins();
|
|
82
46
|
}
|
|
83
47
|
Dispose() {
|
|
@@ -87,10 +51,10 @@ class Client {
|
|
|
87
51
|
* Start a websocket server, and waiting for cluster server to connect
|
|
88
52
|
*/
|
|
89
53
|
Init = async () => {
|
|
90
|
-
let port_result =
|
|
54
|
+
let port_result = PORT;
|
|
91
55
|
let canbeuse = false;
|
|
92
56
|
while (!canbeuse) {
|
|
93
|
-
await
|
|
57
|
+
await check(port_result).then(x => {
|
|
94
58
|
canbeuse = !x;
|
|
95
59
|
}).catch(err => {
|
|
96
60
|
canbeuse = true;
|
|
@@ -116,7 +80,7 @@ class Client {
|
|
|
116
80
|
this.Release();
|
|
117
81
|
});
|
|
118
82
|
this.client.on('connection', (ws, request) => {
|
|
119
|
-
const a = new
|
|
83
|
+
const a = new ClientAnalysis(this.messager, this.messager_log, this);
|
|
120
84
|
this.analysis.push(a);
|
|
121
85
|
this.sources.push(ws);
|
|
122
86
|
this.messager_log(`[Server] New Connection detected, ${ws.url}`);
|
|
@@ -156,11 +120,11 @@ class Client {
|
|
|
156
120
|
this.analysis = [];
|
|
157
121
|
};
|
|
158
122
|
savePlugin = () => {
|
|
159
|
-
const f = path.join(os.homedir(),
|
|
123
|
+
const f = path.join(os.homedir(), DATA_FOLDER);
|
|
160
124
|
const pluginPath = path.join(f, 'plugin.json');
|
|
161
|
-
if (!
|
|
162
|
-
|
|
163
|
-
|
|
125
|
+
if (!existsSync(f))
|
|
126
|
+
mkdirSync(f, { recursive: true });
|
|
127
|
+
writeFileSync(pluginPath, JSON.stringify(this.plugins, null, 4));
|
|
164
128
|
};
|
|
165
129
|
/**
|
|
166
130
|
* The node update function, It will do things below
|
|
@@ -170,33 +134,33 @@ class Client {
|
|
|
170
134
|
this.analysis.forEach(x => x.update(this));
|
|
171
135
|
};
|
|
172
136
|
loadPlugins = () => {
|
|
173
|
-
const f = path.join(os.homedir(),
|
|
137
|
+
const f = path.join(os.homedir(), DATA_FOLDER, "node_plugin");
|
|
174
138
|
const pluginPath = path.join(f, 'plugin.json');
|
|
175
|
-
if (!
|
|
176
|
-
|
|
177
|
-
if (!
|
|
178
|
-
|
|
139
|
+
if (!existsSync(f))
|
|
140
|
+
mkdirSync(f, { recursive: true });
|
|
141
|
+
if (!existsSync(pluginPath)) {
|
|
142
|
+
writeFileSync(pluginPath, JSON.stringify(this.plugins, null, 4));
|
|
179
143
|
}
|
|
180
144
|
else {
|
|
181
|
-
this.plugins = JSON.parse(
|
|
145
|
+
this.plugins = JSON.parse(readFileSync(pluginPath).toString());
|
|
182
146
|
}
|
|
183
147
|
};
|
|
184
148
|
get_pem = () => {
|
|
185
149
|
return new Promise((resolve) => {
|
|
186
|
-
const pemFolder = path.join(os.homedir(),
|
|
187
|
-
if (!
|
|
188
|
-
|
|
150
|
+
const pemFolder = path.join(os.homedir(), DATA_FOLDER, 'pem');
|
|
151
|
+
if (!existsSync(pemFolder))
|
|
152
|
+
mkdirSync(pemFolder);
|
|
189
153
|
const clientKey = path.join(pemFolder, "client_clientkey.pem");
|
|
190
154
|
const certificate = path.join(pemFolder, "client_certificate.pem");
|
|
191
|
-
if (!
|
|
155
|
+
if (!existsSync(clientKey) || !existsSync(certificate)) {
|
|
192
156
|
pem.createCertificate({ selfSigned: true }, (err, keys) => {
|
|
193
|
-
|
|
194
|
-
|
|
157
|
+
writeFileSync(clientKey, keys.clientKey, { encoding: 'utf8' });
|
|
158
|
+
writeFileSync(certificate, keys.certificate, { encoding: 'utf8' });
|
|
195
159
|
resolve([keys.clientKey, keys.certificate]);
|
|
196
160
|
});
|
|
197
161
|
}
|
|
198
162
|
else {
|
|
199
|
-
resolve([
|
|
163
|
+
resolve([readFileSync(clientKey, 'utf8').toString(), readFileSync(certificate, 'utf8').toString()]);
|
|
200
164
|
}
|
|
201
165
|
});
|
|
202
166
|
};
|
|
@@ -254,4 +218,3 @@ class Client {
|
|
|
254
218
|
}
|
|
255
219
|
};
|
|
256
220
|
}
|
|
257
|
-
exports.Client = Client;
|
package/dist/client/cluster.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RUN = RUN;
|
|
4
1
|
// ========================
|
|
5
2
|
//
|
|
6
3
|
// Share Codebase
|
|
7
4
|
//
|
|
8
5
|
// ========================
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import { ResourceType } from '../interface';
|
|
7
|
+
import { ClientHTTP } from './http';
|
|
8
|
+
import { ClientJobExecute } from './job_execute';
|
|
9
|
+
import { ClientResource } from './resource';
|
|
13
10
|
let worker = undefined;
|
|
14
11
|
process.stdin.resume();
|
|
15
12
|
process.stdin.setEncoding('utf8');
|
|
@@ -69,7 +66,7 @@ const execute_job = () => {
|
|
|
69
66
|
}
|
|
70
67
|
const d = JSON.parse(process.env.job);
|
|
71
68
|
const p = JSON.parse(process.env.plugin);
|
|
72
|
-
worker = new
|
|
69
|
+
worker = new ClientJobExecute(messager, messager_log, d, undefined, p);
|
|
73
70
|
worker.execute().then(x => {
|
|
74
71
|
messager_log(x);
|
|
75
72
|
process.exit(0);
|
|
@@ -80,10 +77,10 @@ const execute_job = () => {
|
|
|
80
77
|
* Query resource task
|
|
81
78
|
*/
|
|
82
79
|
const execute_resource = () => {
|
|
83
|
-
const r = new
|
|
80
|
+
const r = new ClientResource();
|
|
84
81
|
messager("Resource query");
|
|
85
82
|
const cache = process.env.cache == undefined ? undefined : JSON.parse(process.env.cache);
|
|
86
|
-
const type = cache == undefined ?
|
|
83
|
+
const type = cache == undefined ? ResourceType.ALL : ResourceType.BATTERY | ResourceType.LOAD | ResourceType.NETWORK | ResourceType.RAM;
|
|
87
84
|
r.Query(cache, type).then(x => {
|
|
88
85
|
const h = {
|
|
89
86
|
name: 'resource',
|
|
@@ -99,13 +96,13 @@ const execute_http = () => {
|
|
|
99
96
|
const m = process.env.method || 'GET';
|
|
100
97
|
const u = process.env.url || '';
|
|
101
98
|
const p = process.env.params;
|
|
102
|
-
const r = new
|
|
99
|
+
const r = new ClientHTTP(u, m, p);
|
|
103
100
|
r.RUN();
|
|
104
101
|
};
|
|
105
102
|
/**
|
|
106
103
|
* The entry point for the cluster thread.
|
|
107
104
|
*/
|
|
108
|
-
function RUN() {
|
|
105
|
+
export function RUN() {
|
|
109
106
|
// The cluster currently spawn should execute a job
|
|
110
107
|
switch (process.env.type) {
|
|
111
108
|
case 'JOB':
|
package/dist/client/database.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientDatabase = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* The database feedback helper\
|
|
6
3
|
* Update the main database container on the cluster server
|
|
7
4
|
*/
|
|
8
|
-
class ClientDatabase {
|
|
5
|
+
export class ClientDatabase {
|
|
9
6
|
source;
|
|
10
7
|
constructor(_source) {
|
|
11
8
|
this.source = _source;
|
|
@@ -50,4 +47,3 @@ class ClientDatabase {
|
|
|
50
47
|
this.source.send(JSON.stringify(p, null, 2));
|
|
51
48
|
};
|
|
52
49
|
}
|
|
53
|
-
exports.ClientDatabase = ClientDatabase;
|
package/dist/client/execute.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientExecute = void 0;
|
|
4
1
|
// ========================
|
|
5
2
|
//
|
|
6
3
|
// Share Codebase
|
|
7
4
|
//
|
|
8
5
|
// ========================
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
import { WebSocket } from 'ws';
|
|
8
|
+
import { DataType, JobCategory, JobType2Text, JobTypeText } from "../interface";
|
|
9
|
+
import { i18n } from "../plugins/i18n";
|
|
10
|
+
import { Client } from "./client";
|
|
11
|
+
import { ClientDatabase } from './database';
|
|
15
12
|
/**
|
|
16
13
|
* Execute worker, Execute the job container
|
|
17
14
|
*/
|
|
18
|
-
class ClientExecute {
|
|
15
|
+
export class ClientExecute {
|
|
19
16
|
uuid;
|
|
20
17
|
database = undefined;
|
|
21
18
|
libraries = undefined;
|
|
@@ -50,12 +47,12 @@ class ClientExecute {
|
|
|
50
47
|
* @param job Target job
|
|
51
48
|
*/
|
|
52
49
|
execute_job = (job, source) => {
|
|
53
|
-
this.messager_log(`[Execute] ${job.uuid} ${job.category ==
|
|
50
|
+
this.messager_log(`[Execute] ${job.uuid} ${job.category == JobCategory.Execution ? i18n.global.t(JobTypeText[job.type]) : i18n.global.t(JobType2Text[job.type])}`, job.uuid, job.runtime_uuid);
|
|
54
51
|
this.tag = job.uuid;
|
|
55
52
|
this.execute_job_worker(job, source);
|
|
56
53
|
};
|
|
57
54
|
execute_job_worker(job, source) {
|
|
58
|
-
const child =
|
|
55
|
+
const child = spawn(Client.workerPath(), [], {
|
|
59
56
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
60
57
|
windowsHide: true,
|
|
61
58
|
shell: true,
|
|
@@ -70,7 +67,7 @@ class ClientExecute {
|
|
|
70
67
|
});
|
|
71
68
|
child.stdin.setDefaultEncoding('utf-8');
|
|
72
69
|
this.workers.push(child);
|
|
73
|
-
const para = new
|
|
70
|
+
const para = new ClientDatabase(source);
|
|
74
71
|
let k = "";
|
|
75
72
|
const workerFeedbackExec = (str) => {
|
|
76
73
|
try {
|
|
@@ -148,7 +145,7 @@ class ClientExecute {
|
|
|
148
145
|
`[Execute] Error: ${code} ${signal}`, job.uuid, job.runtime_uuid);
|
|
149
146
|
const data = { job_uuid: job.uuid, runtime_uuid: job.runtime_uuid, meta: code, message: signal };
|
|
150
147
|
const h = { name: 'feedback_job', data: data };
|
|
151
|
-
if (source.readyState ==
|
|
148
|
+
if (source.readyState == WebSocket.OPEN) {
|
|
152
149
|
source.send(JSON.stringify(h));
|
|
153
150
|
}
|
|
154
151
|
this.tag = '';
|
|
@@ -175,7 +172,7 @@ class ClientExecute {
|
|
|
175
172
|
set_string = (data) => {
|
|
176
173
|
if (this.database == undefined)
|
|
177
174
|
return;
|
|
178
|
-
const index = this.database.containers.findIndex(x => x.name == data.key && x.type ==
|
|
175
|
+
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == DataType.String);
|
|
179
176
|
if (index != -1)
|
|
180
177
|
this.database.containers[index].value = data.value;
|
|
181
178
|
this.messager_log(`[Database string sync] ${data.key} = ${data.value}`);
|
|
@@ -188,7 +185,7 @@ class ClientExecute {
|
|
|
188
185
|
set_number = (data) => {
|
|
189
186
|
if (this.database == undefined)
|
|
190
187
|
return;
|
|
191
|
-
const index = this.database.containers.findIndex(x => x.name == data.key && x.type ==
|
|
188
|
+
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == DataType.Number);
|
|
192
189
|
if (index != -1)
|
|
193
190
|
this.database.containers[index].value = data.value;
|
|
194
191
|
this.messager_log(`[Database number sync] ${data.key} = ${data.value}`);
|
|
@@ -201,10 +198,9 @@ class ClientExecute {
|
|
|
201
198
|
set_boolean = (data) => {
|
|
202
199
|
if (this.database == undefined)
|
|
203
200
|
return;
|
|
204
|
-
const index = this.database.containers.findIndex(x => x.name == data.key && x.type ==
|
|
201
|
+
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == DataType.Boolean);
|
|
205
202
|
if (index != -1)
|
|
206
203
|
this.database.containers[index].value = data.value;
|
|
207
204
|
this.messager_log(`[Database boolean sync] ${data.key} = ${data.value}`);
|
|
208
205
|
};
|
|
209
206
|
}
|
|
210
|
-
exports.ClientExecute = ClientExecute;
|
package/dist/client/http.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientHTTP = void 0;
|
|
4
|
-
class ClientHTTP {
|
|
1
|
+
export class ClientHTTP {
|
|
5
2
|
url;
|
|
6
3
|
method;
|
|
7
4
|
params;
|
|
@@ -37,4 +34,3 @@ class ClientHTTP {
|
|
|
37
34
|
});
|
|
38
35
|
};
|
|
39
36
|
}
|
|
40
|
-
exports.ClientHTTP = ClientHTTP;
|