verteilen-core 1.2.3 → 1.2.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/dist/index.d.ts +3 -0
- package/dist/jest.config.d.ts +2 -0
- package/dist/src/client/analysis.d.ts +35 -0
- package/dist/src/client/analysis.js +318 -319
- package/dist/src/client/client.d.ts +25 -0
- package/dist/src/client/client.js +162 -168
- package/dist/src/client/cluster.d.ts +1 -0
- package/dist/src/client/cluster.js +1 -2
- package/dist/src/client/database.d.ts +13 -0
- package/dist/src/client/database.js +28 -27
- package/dist/src/client/execute.d.ts +24 -0
- package/dist/src/client/execute.js +61 -51
- package/dist/src/client/http.d.ts +7 -0
- package/dist/src/client/http.js +29 -26
- package/dist/src/client/javascript.d.ts +47 -0
- package/dist/src/client/javascript.js +110 -136
- package/dist/src/client/job_database.d.ts +10 -0
- package/dist/src/client/job_database.js +27 -29
- package/dist/src/client/job_execute.d.ts +20 -0
- package/dist/src/client/job_execute.js +148 -146
- package/dist/src/client/os.d.ts +29 -0
- package/dist/src/client/os.js +131 -136
- package/dist/src/client/resource.d.ts +7 -0
- package/dist/src/client/resource.js +93 -104
- package/dist/src/client/shell.d.ts +16 -0
- package/dist/src/client/shell.js +102 -98
- package/dist/src/computed.d.ts +13 -0
- package/dist/src/interface/base.d.ts +70 -0
- package/dist/src/interface/bus.d.ts +90 -0
- package/dist/src/interface/enum.d.ts +143 -0
- package/dist/src/interface/enum.js +5 -5
- package/dist/src/interface/execute.d.ts +20 -0
- package/dist/src/interface/record.d.ts +93 -0
- package/dist/src/interface/server.d.ts +76 -0
- package/dist/src/interface/struct.d.ts +182 -0
- package/dist/src/interface/table.d.ts +20 -0
- package/dist/src/interface/ui.d.ts +29 -0
- package/dist/src/interface.d.ts +29 -0
- package/dist/src/plugins/i18n.d.ts +1666 -0
- package/dist/src/script/console_manager.d.ts +18 -0
- package/dist/src/script/console_manager.js +97 -91
- package/dist/src/script/console_server_manager.d.ts +13 -0
- package/dist/src/script/console_server_manager.js +29 -26
- package/dist/src/script/execute/base.d.ts +45 -0
- package/dist/src/script/execute/base.js +165 -162
- package/dist/src/script/execute/feedback.d.ts +12 -0
- package/dist/src/script/execute/feedback.js +162 -171
- package/dist/src/script/execute/interface.d.ts +8 -0
- package/dist/src/script/execute/region_job.d.ts +5 -0
- package/dist/src/script/execute/region_job.js +1 -0
- package/dist/src/script/execute/region_project.d.ts +10 -0
- package/dist/src/script/execute/region_project.js +4 -0
- package/dist/src/script/execute/region_subtask.d.ts +5 -0
- package/dist/src/script/execute/region_subtask.js +1 -0
- package/dist/src/script/execute/region_task.d.ts +10 -0
- package/dist/src/script/execute/region_task.js +4 -0
- package/dist/src/script/execute/runner.d.ts +14 -0
- package/dist/src/script/execute/runner.js +129 -139
- package/dist/src/script/execute/util_parser.d.ts +14 -0
- package/dist/src/script/execute/util_parser.js +119 -121
- package/dist/src/script/execute_manager.d.ts +25 -0
- package/dist/src/script/execute_manager.js +266 -278
- package/dist/src/script/socket_manager.d.ts +31 -0
- package/dist/src/script/socket_manager.js +196 -193
- package/dist/src/script/webhook_manager.d.ts +3 -0
- package/dist/src/script/webhook_server_manager.d.ts +13 -0
- package/dist/src/script/webhook_server_manager.js +79 -86
- package/dist/src/server/detail.d.ts +72 -0
- package/dist/src/server/detail.js +401 -378
- package/dist/src/server/io.d.ts +46 -0
- package/dist/src/server/io.js +42 -51
- package/dist/src/server/plugin.d.ts +18 -0
- package/dist/src/server/plugin.js +45 -54
- package/dist/src/server/server.d.ts +27 -0
- package/dist/src/server/server.js +38 -36
- package/dist/src/server.d.ts +4 -0
- package/dist/src/util/console_handle.d.ts +20 -0
- package/dist/src/util/console_handle.js +214 -218
- package/dist/src/util/log_handle.d.ts +23 -0
- package/dist/src/util/log_handle.js +158 -164
- package/dist/test/TEST.d.ts +1 -0
- package/dist/test/TEST.js +37 -54
- package/dist/test/client/execute.test.d.ts +1 -0
- package/dist/test/client/execute.test.js +6 -15
- package/dist/test/client/javascript.test.d.ts +1 -0
- package/dist/test/client/javascript.test.js +21 -30
- package/dist/test/client/server.test.d.ts +1 -0
- package/dist/test/client/task.test.d.ts +1 -0
- package/dist/test/client/task.test.js +1 -1
- package/dist/test/script/parser.test.d.ts +1 -0
- package/dist/test/script/socket.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/interface/enum.ts +1 -1
- package/tsconfig.json +5 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
import { Messager, Messager_log, PluginList } from '../interface';
|
|
3
|
+
export declare class Client {
|
|
4
|
+
plugins: PluginList;
|
|
5
|
+
private httpss;
|
|
6
|
+
private client;
|
|
7
|
+
private sources;
|
|
8
|
+
private messager;
|
|
9
|
+
private messager_log;
|
|
10
|
+
private analysis;
|
|
11
|
+
private updatehandle;
|
|
12
|
+
get count(): number;
|
|
13
|
+
get clients(): Array<WebSocket>;
|
|
14
|
+
constructor(_messager: Messager, _messager_log: Messager_log);
|
|
15
|
+
Dispose(): void;
|
|
16
|
+
Init: () => Promise<void>;
|
|
17
|
+
Destroy: () => void;
|
|
18
|
+
Release: () => void;
|
|
19
|
+
savePlugin: () => void;
|
|
20
|
+
private update;
|
|
21
|
+
private loadPlugins;
|
|
22
|
+
private get_pem;
|
|
23
|
+
static workerPath: (filename?: string, extension?: string) => string;
|
|
24
|
+
static isTypescript: () => boolean;
|
|
25
|
+
}
|
|
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
36
|
exports.Client = void 0;
|
|
46
37
|
const path = __importStar(require("path"));
|
|
@@ -53,6 +44,14 @@ const os = __importStar(require("os"));
|
|
|
53
44
|
const pem = __importStar(require("pem"));
|
|
54
45
|
const https = __importStar(require("https"));
|
|
55
46
|
class Client {
|
|
47
|
+
plugins = { plugins: [] };
|
|
48
|
+
httpss = undefined;
|
|
49
|
+
client = undefined;
|
|
50
|
+
sources = [];
|
|
51
|
+
messager;
|
|
52
|
+
messager_log;
|
|
53
|
+
analysis;
|
|
54
|
+
updatehandle;
|
|
56
55
|
get count() {
|
|
57
56
|
return this.sources.length;
|
|
58
57
|
}
|
|
@@ -60,174 +59,169 @@ class Client {
|
|
|
60
59
|
return this.sources;
|
|
61
60
|
}
|
|
62
61
|
constructor(_messager, _messager_log) {
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this.httpss = https.createServer({ key: pems[0], cert: pems[1], minVersion: 'TLSv1.2', maxVersion: 'TLSv1.3' }, (req, res) => {
|
|
81
|
-
res.writeHead(200);
|
|
82
|
-
res.end('HTTPS server is running');
|
|
83
|
-
});
|
|
84
|
-
this.httpss.addListener('upgrade', (req, res, head) => console.log('UPGRADE:', req.url));
|
|
85
|
-
this.client = new ws.Server({ server: this.httpss });
|
|
86
|
-
this.client.on('listening', () => {
|
|
87
|
-
this.messager_log('[Server] Listen PORT: ' + port_result.toString());
|
|
62
|
+
this.messager = _messager;
|
|
63
|
+
this.messager_log = _messager_log;
|
|
64
|
+
this.analysis = [];
|
|
65
|
+
this.updatehandle = setInterval(this.update, interface_1.CLIENT_UPDATETICK);
|
|
66
|
+
this.loadPlugins();
|
|
67
|
+
}
|
|
68
|
+
Dispose() {
|
|
69
|
+
clearInterval(this.updatehandle);
|
|
70
|
+
}
|
|
71
|
+
Init = async () => {
|
|
72
|
+
let port_result = interface_1.PORT;
|
|
73
|
+
let canbeuse = false;
|
|
74
|
+
while (!canbeuse) {
|
|
75
|
+
await (0, tcp_port_used_1.check)(port_result).then(x => {
|
|
76
|
+
canbeuse = !x;
|
|
77
|
+
}).catch(err => {
|
|
78
|
+
canbeuse = true;
|
|
88
79
|
});
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
if (!canbeuse)
|
|
81
|
+
port_result += 1;
|
|
82
|
+
}
|
|
83
|
+
const pems = await this.get_pem();
|
|
84
|
+
this.httpss = https.createServer({ key: pems[0], cert: pems[1], minVersion: 'TLSv1.2', maxVersion: 'TLSv1.3' }, (req, res) => {
|
|
85
|
+
res.writeHead(200);
|
|
86
|
+
res.end('HTTPS server is running');
|
|
87
|
+
});
|
|
88
|
+
this.httpss.addListener('upgrade', (req, res, head) => console.log('UPGRADE:', req.url));
|
|
89
|
+
this.client = new ws.Server({ server: this.httpss });
|
|
90
|
+
this.client.on('listening', () => {
|
|
91
|
+
this.messager_log('[Server] Listen PORT: ' + port_result.toString());
|
|
92
|
+
});
|
|
93
|
+
this.client.on('error', (err) => {
|
|
94
|
+
this.messager_log(`[Server] Error ${err.name}\n\t${err.message}\n\t${err.stack}`);
|
|
95
|
+
});
|
|
96
|
+
this.client.on('close', () => {
|
|
97
|
+
this.messager_log('[Server] Close !');
|
|
98
|
+
this.Release();
|
|
99
|
+
});
|
|
100
|
+
this.client.on('connection', (ws, request) => {
|
|
101
|
+
const a = new analysis_1.ClientAnalysis(this.messager, this.messager_log, this);
|
|
102
|
+
this.analysis.push(a);
|
|
103
|
+
this.sources.push(ws);
|
|
104
|
+
this.messager_log(`[Server] New Connection detected, ${ws.url}`);
|
|
105
|
+
ws.on('close', (code, reason) => {
|
|
106
|
+
const index = this.sources.findIndex(x => x == ws);
|
|
107
|
+
if (index != -1)
|
|
108
|
+
this.sources.splice(index, 1);
|
|
109
|
+
this.messager_log(`[Source] Close ${code} ${reason}`);
|
|
110
|
+
a.disconnect(ws);
|
|
91
111
|
});
|
|
92
|
-
|
|
93
|
-
this.messager_log(
|
|
94
|
-
this.Release();
|
|
112
|
+
ws.on('error', (err) => {
|
|
113
|
+
this.messager_log(`[Source] Error ${err.name}\n\t${err.message}\n\t${err.stack}`);
|
|
95
114
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.analysis.push(a);
|
|
99
|
-
this.sources.push(ws);
|
|
100
|
-
this.messager_log(`[Server] New Connection detected, ${ws.url}`);
|
|
101
|
-
ws.on('close', (code, reason) => {
|
|
102
|
-
const index = this.sources.findIndex(x => x == ws);
|
|
103
|
-
if (index != -1)
|
|
104
|
-
this.sources.splice(index, 1);
|
|
105
|
-
this.messager_log(`[Source] Close ${code} ${reason}`);
|
|
106
|
-
a.disconnect(ws);
|
|
107
|
-
});
|
|
108
|
-
ws.on('error', (err) => {
|
|
109
|
-
this.messager_log(`[Source] Error ${err.name}\n\t${err.message}\n\t${err.stack}`);
|
|
110
|
-
});
|
|
111
|
-
ws.on('open', () => {
|
|
112
|
-
this.messager_log(`[Source] New source is connected, URL: ${ws === null || ws === void 0 ? void 0 : ws.url}`);
|
|
113
|
-
});
|
|
114
|
-
ws.on('message', (data, isBinery) => {
|
|
115
|
-
const h = JSON.parse(data.toString());
|
|
116
|
-
a.analysis(h, ws);
|
|
117
|
-
});
|
|
115
|
+
ws.on('open', () => {
|
|
116
|
+
this.messager_log(`[Source] New source is connected, URL: ${ws?.url}`);
|
|
118
117
|
});
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
ws.on('message', (data, isBinery) => {
|
|
119
|
+
const h = JSON.parse(data.toString());
|
|
120
|
+
a.analysis(h, ws);
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
-
this.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
123
|
+
this.httpss.listen(port_result, () => {
|
|
124
|
+
this.messager_log('[Server] Select Port: ' + port_result.toString());
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
Destroy = () => {
|
|
128
|
+
if (this.client == undefined)
|
|
129
|
+
return;
|
|
130
|
+
this.client.close((err) => {
|
|
131
|
+
this.messager_log(`[Client] Close error ${err}`);
|
|
132
|
+
});
|
|
133
|
+
this.Release();
|
|
134
|
+
};
|
|
135
|
+
Release = () => {
|
|
136
|
+
this.analysis.forEach(x => x.stop_all());
|
|
137
|
+
this.analysis.forEach(x => x.destroy());
|
|
138
|
+
this.analysis = [];
|
|
139
|
+
};
|
|
140
|
+
savePlugin = () => {
|
|
141
|
+
const f = path.join(os.homedir(), interface_1.DATA_FOLDER);
|
|
142
|
+
const pluginPath = path.join(f, 'plugin.json');
|
|
143
|
+
if (!(0, fs_1.existsSync)(f))
|
|
144
|
+
(0, fs_1.mkdirSync)(f, { recursive: true });
|
|
145
|
+
(0, fs_1.writeFileSync)(pluginPath, JSON.stringify(this.plugins, null, 4));
|
|
146
|
+
};
|
|
147
|
+
update = () => {
|
|
148
|
+
this.analysis.forEach(x => x.update(this));
|
|
149
|
+
};
|
|
150
|
+
loadPlugins = () => {
|
|
151
|
+
const f = path.join(os.homedir(), interface_1.DATA_FOLDER);
|
|
152
|
+
const pluginPath = path.join(f, 'plugin.json');
|
|
153
|
+
if (!(0, fs_1.existsSync)(f))
|
|
154
|
+
(0, fs_1.mkdirSync)(f, { recursive: true });
|
|
155
|
+
if (!(0, fs_1.existsSync)(pluginPath)) {
|
|
141
156
|
(0, fs_1.writeFileSync)(pluginPath, JSON.stringify(this.plugins, null, 4));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this.
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
this.plugins = JSON.parse((0, fs_1.readFileSync)(pluginPath).toString());
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
get_pem = () => {
|
|
163
|
+
return new Promise((resolve) => {
|
|
164
|
+
const pemFolder = path.join(os.homedir(), interface_1.DATA_FOLDER, 'pem');
|
|
165
|
+
if (!(0, fs_1.existsSync)(pemFolder))
|
|
166
|
+
(0, fs_1.mkdirSync)(pemFolder);
|
|
167
|
+
const clientKey = path.join(pemFolder, "client_clientkey.pem");
|
|
168
|
+
const certificate = path.join(pemFolder, "client_certificate.pem");
|
|
169
|
+
if (!(0, fs_1.existsSync)(clientKey) || !(0, fs_1.existsSync)(certificate)) {
|
|
170
|
+
pem.createCertificate({ selfSigned: true }, (err, keys) => {
|
|
171
|
+
(0, fs_1.writeFileSync)(clientKey, keys.clientKey, { encoding: 'utf8' });
|
|
172
|
+
(0, fs_1.writeFileSync)(certificate, keys.certificate, { encoding: 'utf8' });
|
|
173
|
+
resolve([keys.clientKey, keys.certificate]);
|
|
174
|
+
});
|
|
153
175
|
}
|
|
154
176
|
else {
|
|
155
|
-
|
|
177
|
+
resolve([(0, fs_1.readFileSync)(clientKey, 'utf8').toString(), (0, fs_1.readFileSync)(certificate, 'utf8').toString()]);
|
|
156
178
|
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
static workerPath = (filename = "worker", extension = ".exe") => {
|
|
182
|
+
const isExe = process.pkg?.entrypoint != undefined;
|
|
183
|
+
const exe = process.platform == 'win32' ? filename + extension : filename;
|
|
184
|
+
let workerExe = "";
|
|
185
|
+
let p = 0;
|
|
186
|
+
if (isExe && path.basename(process.execPath) == (process.platform ? "app.exe" : 'app')) {
|
|
187
|
+
workerExe = path.join(process.execPath, "..", "bin", exe);
|
|
188
|
+
p = 1;
|
|
189
|
+
}
|
|
190
|
+
else if ((process.mainModule && process.mainModule.filename.indexOf('app.asar') !== -1) ||
|
|
191
|
+
process.argv.filter(a => a.indexOf('app.asar') !== -1).length > 0) {
|
|
192
|
+
workerExe = path.join("bin", exe);
|
|
193
|
+
p = 2;
|
|
194
|
+
}
|
|
195
|
+
else if (process.env.NODE_ENV === 'development') {
|
|
196
|
+
workerExe = path.join(process.cwd(), "bin", exe);
|
|
197
|
+
p = 3;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
workerExe = Client.isTypescript() ? path.join(__dirname, "bin", exe) : path.join(__dirname, "..", "bin", exe);
|
|
201
|
+
p = 4;
|
|
202
|
+
}
|
|
203
|
+
return workerExe;
|
|
204
|
+
};
|
|
205
|
+
static isTypescript = () => {
|
|
206
|
+
const extension = path.extname(__filename);
|
|
207
|
+
if (extension === ".ts") {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
const lastArg = process.execArgv[process.execArgv.length - 1];
|
|
211
|
+
if (lastArg && path.parse(lastArg).name.indexOf("ts-node") > 0) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
return process[Symbol.for("ts-node.register.instance")] ||
|
|
216
|
+
(process.env.NODE_ENV === "test" &&
|
|
217
|
+
process.env.ACTIONHERO_TEST_FILE_EXTENSION !== "js")
|
|
218
|
+
? true
|
|
219
|
+
: false;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
console.error(error);
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
186
226
|
}
|
|
187
227
|
exports.Client = Client;
|
|
188
|
-
Client.workerPath = (filename = "worker", extension = ".exe") => {
|
|
189
|
-
var _a;
|
|
190
|
-
const isExe = ((_a = process.pkg) === null || _a === void 0 ? void 0 : _a.entrypoint) != undefined;
|
|
191
|
-
const exe = process.platform == 'win32' ? filename + extension : filename;
|
|
192
|
-
let workerExe = "";
|
|
193
|
-
let p = 0;
|
|
194
|
-
if (isExe && path.basename(process.execPath) == (process.platform ? "app.exe" : 'app')) {
|
|
195
|
-
workerExe = path.join(process.execPath, "..", "bin", exe);
|
|
196
|
-
p = 1;
|
|
197
|
-
}
|
|
198
|
-
else if ((process.mainModule && process.mainModule.filename.indexOf('app.asar') !== -1) ||
|
|
199
|
-
process.argv.filter(a => a.indexOf('app.asar') !== -1).length > 0) {
|
|
200
|
-
workerExe = path.join("bin", exe);
|
|
201
|
-
p = 2;
|
|
202
|
-
}
|
|
203
|
-
else if (process.env.NODE_ENV === 'development') {
|
|
204
|
-
workerExe = path.join(process.cwd(), "bin", exe);
|
|
205
|
-
p = 3;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
workerExe = Client.isTypescript() ? path.join(__dirname, "bin", exe) : path.join(__dirname, "..", "bin", exe);
|
|
209
|
-
p = 4;
|
|
210
|
-
}
|
|
211
|
-
return workerExe;
|
|
212
|
-
};
|
|
213
|
-
Client.isTypescript = () => {
|
|
214
|
-
const extension = path.extname(__filename);
|
|
215
|
-
if (extension === ".ts") {
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
const lastArg = process.execArgv[process.execArgv.length - 1];
|
|
219
|
-
if (lastArg && path.parse(lastArg).name.indexOf("ts-node") > 0) {
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
return process[Symbol.for("ts-node.register.instance")] ||
|
|
224
|
-
(process.env.NODE_ENV === "test" &&
|
|
225
|
-
process.env.ACTIONHERO_TEST_FILE_EXTENSION !== "js")
|
|
226
|
-
? true
|
|
227
|
-
: false;
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
console.error(error);
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function RUN(): void;
|
|
@@ -33,11 +33,10 @@ const messager_log = (msg, tag, meta) => {
|
|
|
33
33
|
console.log(JSON.stringify(d));
|
|
34
34
|
};
|
|
35
35
|
const ERROR = (err) => {
|
|
36
|
-
var _a;
|
|
37
36
|
const d = {
|
|
38
37
|
name: "error",
|
|
39
38
|
meta: "Execute job failed",
|
|
40
|
-
data: `(${
|
|
39
|
+
data: `(${err.code ?? 'unknown'}) ${err.message}`,
|
|
41
40
|
};
|
|
42
41
|
console.log(JSON.stringify(d));
|
|
43
42
|
process.exit(1);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
import { Setter } from "../interface";
|
|
3
|
+
export declare class ClientDatabase {
|
|
4
|
+
private source;
|
|
5
|
+
constructor(_source: WebSocket | undefined);
|
|
6
|
+
feedbacknumber: (data: Setter) => void;
|
|
7
|
+
feedbackboolean: (data: Setter) => void;
|
|
8
|
+
feedbackstring: (data: Setter) => void;
|
|
9
|
+
feedbackobject: (data: Setter) => void;
|
|
10
|
+
feedbacklist: (data: Setter) => void;
|
|
11
|
+
feedbackselect: (data: Setter) => void;
|
|
12
|
+
private feedback;
|
|
13
|
+
}
|
|
@@ -2,35 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClientDatabase = void 0;
|
|
4
4
|
class ClientDatabase {
|
|
5
|
+
source;
|
|
5
6
|
constructor(_source) {
|
|
6
|
-
this.feedbacknumber = (data) => {
|
|
7
|
-
this.feedback("feedback_number", data);
|
|
8
|
-
};
|
|
9
|
-
this.feedbackboolean = (data) => {
|
|
10
|
-
this.feedback("feedback_boolean", data);
|
|
11
|
-
};
|
|
12
|
-
this.feedbackstring = (data) => {
|
|
13
|
-
this.feedback("feedback_string", data);
|
|
14
|
-
};
|
|
15
|
-
this.feedbackobject = (data) => {
|
|
16
|
-
this.feedback("feedback_object", data);
|
|
17
|
-
};
|
|
18
|
-
this.feedbacklist = (data) => {
|
|
19
|
-
this.feedback("feedback_list", data);
|
|
20
|
-
};
|
|
21
|
-
this.feedbackselect = (data) => {
|
|
22
|
-
this.feedback("feedback_select", data);
|
|
23
|
-
};
|
|
24
|
-
this.feedback = (title, data) => {
|
|
25
|
-
if (this.source == undefined)
|
|
26
|
-
return;
|
|
27
|
-
const p = {
|
|
28
|
-
name: title,
|
|
29
|
-
data: data
|
|
30
|
-
};
|
|
31
|
-
this.source.send(JSON.stringify(p, null, 2));
|
|
32
|
-
};
|
|
33
7
|
this.source = _source;
|
|
34
8
|
}
|
|
9
|
+
feedbacknumber = (data) => {
|
|
10
|
+
this.feedback("feedback_number", data);
|
|
11
|
+
};
|
|
12
|
+
feedbackboolean = (data) => {
|
|
13
|
+
this.feedback("feedback_boolean", data);
|
|
14
|
+
};
|
|
15
|
+
feedbackstring = (data) => {
|
|
16
|
+
this.feedback("feedback_string", data);
|
|
17
|
+
};
|
|
18
|
+
feedbackobject = (data) => {
|
|
19
|
+
this.feedback("feedback_object", data);
|
|
20
|
+
};
|
|
21
|
+
feedbacklist = (data) => {
|
|
22
|
+
this.feedback("feedback_list", data);
|
|
23
|
+
};
|
|
24
|
+
feedbackselect = (data) => {
|
|
25
|
+
this.feedback("feedback_select", data);
|
|
26
|
+
};
|
|
27
|
+
feedback = (title, data) => {
|
|
28
|
+
if (this.source == undefined)
|
|
29
|
+
return;
|
|
30
|
+
const p = {
|
|
31
|
+
name: title,
|
|
32
|
+
data: data
|
|
33
|
+
};
|
|
34
|
+
this.source.send(JSON.stringify(p, null, 2));
|
|
35
|
+
};
|
|
35
36
|
}
|
|
36
37
|
exports.ClientDatabase = ClientDatabase;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
import { Job, Libraries, Messager, Messager_log, Database, Setter } from "../interface";
|
|
3
|
+
import { Client } from "./client";
|
|
4
|
+
export declare class ClientExecute {
|
|
5
|
+
uuid: string;
|
|
6
|
+
private database;
|
|
7
|
+
private libraries;
|
|
8
|
+
private tag;
|
|
9
|
+
private workers;
|
|
10
|
+
private client;
|
|
11
|
+
private messager;
|
|
12
|
+
private messager_log;
|
|
13
|
+
get count(): number;
|
|
14
|
+
constructor(_uuid: string, _messager: Messager, _messager_log: Messager_log, _client: Client);
|
|
15
|
+
stop_job: () => void;
|
|
16
|
+
execute_job: (job: Job, source: WebSocket) => void;
|
|
17
|
+
private execute_job_worker;
|
|
18
|
+
private job_finish;
|
|
19
|
+
set_database: (data: Database) => void;
|
|
20
|
+
set_libs: (data: Libraries) => void;
|
|
21
|
+
set_string: (data: Setter) => void;
|
|
22
|
+
set_number: (data: Setter) => void;
|
|
23
|
+
set_boolean: (data: Setter) => void;
|
|
24
|
+
}
|
|
@@ -8,76 +8,56 @@ const i18n_1 = require("../plugins/i18n");
|
|
|
8
8
|
const client_1 = require("./client");
|
|
9
9
|
const database_1 = require("./database");
|
|
10
10
|
class ClientExecute {
|
|
11
|
+
uuid;
|
|
12
|
+
database = undefined;
|
|
13
|
+
libraries = undefined;
|
|
14
|
+
tag = '';
|
|
15
|
+
workers = [];
|
|
16
|
+
client;
|
|
17
|
+
messager;
|
|
18
|
+
messager_log;
|
|
11
19
|
get count() {
|
|
12
20
|
return this.workers.length;
|
|
13
21
|
}
|
|
14
22
|
constructor(_uuid, _messager, _messager_log, _client) {
|
|
15
|
-
this.database = undefined;
|
|
16
|
-
this.libraries = undefined;
|
|
17
|
-
this.tag = '';
|
|
18
|
-
this.workers = [];
|
|
19
|
-
this.stop_job = () => {
|
|
20
|
-
this.messager_log(`[Execute] Stop All: ${this.workers.length}`);
|
|
21
|
-
this.workers.forEach(x => {
|
|
22
|
-
x.stdin.cork();
|
|
23
|
-
x.stdin.write("kill\n");
|
|
24
|
-
x.stdin.uncork();
|
|
25
|
-
x.stdin.end();
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
this.execute_job = (job, source) => {
|
|
29
|
-
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);
|
|
30
|
-
this.tag = job.uuid;
|
|
31
|
-
this.execute_job_worker(job, source);
|
|
32
|
-
};
|
|
33
|
-
this.set_database = (data) => {
|
|
34
|
-
this.database = data;
|
|
35
|
-
};
|
|
36
|
-
this.set_libs = (data) => {
|
|
37
|
-
this.libraries = data;
|
|
38
|
-
};
|
|
39
|
-
this.set_string = (data) => {
|
|
40
|
-
if (this.database == undefined)
|
|
41
|
-
return;
|
|
42
|
-
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.String);
|
|
43
|
-
if (index != -1)
|
|
44
|
-
this.database.containers[index].value = data.value;
|
|
45
|
-
this.messager_log(`[Database string sync] ${data.key} = ${data.value}`);
|
|
46
|
-
};
|
|
47
|
-
this.set_number = (data) => {
|
|
48
|
-
if (this.database == undefined)
|
|
49
|
-
return;
|
|
50
|
-
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.Number);
|
|
51
|
-
if (index != -1)
|
|
52
|
-
this.database.containers[index].value = data.value;
|
|
53
|
-
this.messager_log(`[Database number sync] ${data.key} = ${data.value}`);
|
|
54
|
-
};
|
|
55
|
-
this.set_boolean = (data) => {
|
|
56
|
-
if (this.database == undefined)
|
|
57
|
-
return;
|
|
58
|
-
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.Boolean);
|
|
59
|
-
if (index != -1)
|
|
60
|
-
this.database.containers[index].value = data.value;
|
|
61
|
-
this.messager_log(`[Database boolean sync] ${data.key} = ${data.value}`);
|
|
62
|
-
};
|
|
63
23
|
this.uuid = _uuid;
|
|
64
24
|
this.client = _client;
|
|
65
25
|
this.messager = _messager;
|
|
66
26
|
this.messager_log = _messager_log;
|
|
67
27
|
}
|
|
28
|
+
stop_job = () => {
|
|
29
|
+
this.messager_log(`[Execute] Stop All: ${this.workers.length}`);
|
|
30
|
+
this.workers.forEach(x => {
|
|
31
|
+
x.stdin.cork();
|
|
32
|
+
x.stdin.write("kill\n");
|
|
33
|
+
x.stdin.uncork();
|
|
34
|
+
x.stdin.end();
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
execute_job = (job, source) => {
|
|
38
|
+
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
|
+
this.tag = job.uuid;
|
|
40
|
+
this.execute_job_worker(job, source);
|
|
41
|
+
};
|
|
68
42
|
execute_job_worker(job, source) {
|
|
69
43
|
const child = (0, child_process_1.spawn)(client_1.Client.workerPath(), [], {
|
|
70
44
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
71
45
|
windowsHide: true,
|
|
72
46
|
shell: true,
|
|
73
|
-
env:
|
|
47
|
+
env: {
|
|
48
|
+
...process.env,
|
|
49
|
+
type: "JOB",
|
|
50
|
+
job: JSON.stringify(job),
|
|
51
|
+
plugin: JSON.stringify(this.client.plugins),
|
|
52
|
+
database: JSON.stringify(this.database),
|
|
53
|
+
libraries: JSON.stringify(this.libraries),
|
|
54
|
+
}
|
|
74
55
|
});
|
|
75
56
|
child.stdin.setDefaultEncoding('utf-8');
|
|
76
57
|
this.workers.push(child);
|
|
77
58
|
const para = new database_1.ClientDatabase(source);
|
|
78
59
|
let k = "";
|
|
79
60
|
const workerFeedbackExec = (str) => {
|
|
80
|
-
var _a;
|
|
81
61
|
try {
|
|
82
62
|
const msg = JSON.parse(str);
|
|
83
63
|
if (msg.name == 'messager') {
|
|
@@ -113,7 +93,7 @@ class ClientExecute {
|
|
|
113
93
|
}
|
|
114
94
|
catch (err) {
|
|
115
95
|
this.messager_log(`Error: ${str}`, job.uuid, job.runtime_uuid);
|
|
116
|
-
this.messager_log(`(${
|
|
96
|
+
this.messager_log(`(${err.code ?? 'unknown'}) ${err.message}`, job.uuid, job.runtime_uuid);
|
|
117
97
|
}
|
|
118
98
|
};
|
|
119
99
|
const workerFeedback = (str) => {
|
|
@@ -158,5 +138,35 @@ class ClientExecute {
|
|
|
158
138
|
}
|
|
159
139
|
this.tag = '';
|
|
160
140
|
}
|
|
141
|
+
set_database = (data) => {
|
|
142
|
+
this.database = data;
|
|
143
|
+
};
|
|
144
|
+
set_libs = (data) => {
|
|
145
|
+
this.libraries = data;
|
|
146
|
+
};
|
|
147
|
+
set_string = (data) => {
|
|
148
|
+
if (this.database == undefined)
|
|
149
|
+
return;
|
|
150
|
+
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.String);
|
|
151
|
+
if (index != -1)
|
|
152
|
+
this.database.containers[index].value = data.value;
|
|
153
|
+
this.messager_log(`[Database string sync] ${data.key} = ${data.value}`);
|
|
154
|
+
};
|
|
155
|
+
set_number = (data) => {
|
|
156
|
+
if (this.database == undefined)
|
|
157
|
+
return;
|
|
158
|
+
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.Number);
|
|
159
|
+
if (index != -1)
|
|
160
|
+
this.database.containers[index].value = data.value;
|
|
161
|
+
this.messager_log(`[Database number sync] ${data.key} = ${data.value}`);
|
|
162
|
+
};
|
|
163
|
+
set_boolean = (data) => {
|
|
164
|
+
if (this.database == undefined)
|
|
165
|
+
return;
|
|
166
|
+
const index = this.database.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.Boolean);
|
|
167
|
+
if (index != -1)
|
|
168
|
+
this.database.containers[index].value = data.value;
|
|
169
|
+
this.messager_log(`[Database boolean sync] ${data.key} = ${data.value}`);
|
|
170
|
+
};
|
|
161
171
|
}
|
|
162
172
|
exports.ClientExecute = ClientExecute;
|