verteilen-core 1.2.21 → 1.3.0
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/interface/base.d.ts +26 -12
- package/dist/interface/enum.d.ts +12 -5
- package/dist/interface/enum.js +14 -6
- package/dist/interface/struct.d.ts +9 -1
- package/dist/interface.d.ts +1 -1
- package/dist/interface.js +1 -1
- package/dist/script/execute/base.d.ts +8 -6
- package/dist/script/execute/base.js +21 -8
- package/dist/script/execute/index.d.ts +8 -0
- package/dist/script/execute/index.js +24 -0
- package/dist/script/execute/region_job.d.ts +9 -1
- package/dist/script/execute/region_job.js +62 -2
- package/dist/script/execute/region_project.d.ts +3 -3
- package/dist/script/execute/region_project.js +31 -6
- package/dist/script/execute/region_subtask.d.ts +8 -1
- package/dist/script/execute/region_subtask.js +37 -2
- package/dist/script/execute/region_task.d.ts +32 -4
- package/dist/script/execute/region_task.js +270 -8
- package/dist/script/execute/runner.d.ts +1 -10
- package/dist/script/execute/runner.js +0 -242
- package/dist/script/execute_manager.js +55 -53
- package/dist/server/detail.js +7 -7
- package/dist/server/io.d.ts +5 -1
- package/dist/server/io.js +13 -5
- package/dist/server/module/project.d.ts +14 -0
- package/dist/server/module/project.js +64 -0
- package/dist/server/module/service.d.ts +5 -0
- package/dist/server/module/service.js +10 -0
- package/dist/server/plugin.js +3 -3
- package/dist/server/server.d.ts +7 -2
- package/dist/server/server.js +7 -0
- package/dist/util/console_handle.js +8 -8
- package/dist/util/log_handle.js +4 -4
- package/package.json +1 -1
- package/src/interface/base.ts +104 -31
- package/src/interface/enum.ts +6 -2
- package/src/interface/struct.ts +11 -1
- package/src/interface.ts +1 -1
- package/src/script/execute/base.ts +45 -29
- package/src/script/execute/feedback.ts +1 -3
- package/src/script/execute/region_job.ts +66 -2
- package/src/script/execute/region_project.ts +42 -5
- package/src/script/execute/region_subtask.ts +36 -2
- package/src/script/execute/region_task.ts +348 -9
- package/src/script/execute/runner.ts +1 -306
- package/src/script/execute_manager.ts +61 -61
- package/src/server/detail.ts +12 -7
- package/src/server/io.ts +29 -6
- package/src/server/module/project.ts +82 -0
- package/src/server/module/service.ts +14 -0
- package/src/server/plugin.ts +12 -3
- package/src/server/server.ts +39 -3
- package/src/util/console_handle.ts +8 -8
- package/src/util/log_handle.ts +4 -4
- /package/src/script/execute/{interface.ts → index.ts} +0 -0
|
@@ -2,19 +2,281 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Region_Task = void 0;
|
|
4
4
|
const interface_1 = require("../../interface");
|
|
5
|
+
const region_job_1 = require("./region_job");
|
|
5
6
|
const region_subtask_1 = require("./region_subtask");
|
|
7
|
+
const util_parser_1 = require("./util_parser");
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
6
9
|
class Region_Task {
|
|
7
10
|
target;
|
|
8
|
-
state;
|
|
9
11
|
task;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
multithread = 1;
|
|
13
|
+
task_count = 0;
|
|
14
|
+
cron = [];
|
|
15
|
+
job = [];
|
|
16
|
+
runners = [];
|
|
17
|
+
jrunners = [];
|
|
18
|
+
constructor(target, task) {
|
|
19
|
+
this.target = target;
|
|
20
|
+
this.task = task;
|
|
21
|
+
}
|
|
22
|
+
get project() {
|
|
23
|
+
return this.target.current_p;
|
|
24
|
+
}
|
|
25
|
+
get parent() {
|
|
26
|
+
return this.target.runner;
|
|
27
|
+
}
|
|
28
|
+
RUN = () => {
|
|
29
|
+
if (this.target.t_state == interface_1.ExecuteState.NONE) {
|
|
30
|
+
this.target.t_state = interface_1.ExecuteState.RUNNING;
|
|
31
|
+
this.multithread = this.task.multi ? this.get_task_multi_count(this.task) : 1;
|
|
32
|
+
this.task_count = this.get_task_state_count(this.task);
|
|
33
|
+
}
|
|
34
|
+
let allJobFinish = false;
|
|
35
|
+
const hasJob = this.task.jobs.length > 0;
|
|
36
|
+
if (!hasJob) {
|
|
37
|
+
this.target.proxy?.executeTaskStart([this.task, this.task_count]);
|
|
38
|
+
this.target.proxy?.executeTaskFinish(this.task);
|
|
39
|
+
this.target.messager_log(`[Execute] Skip ! No job exists ${this.task.uuid}`);
|
|
40
|
+
this.ExecuteTask_AllFinish(this.project, this.task);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (this.task.setupjob) {
|
|
44
|
+
allJobFinish = this.ExecuteTask_Setup(this.project, this.task, this.task_count);
|
|
45
|
+
}
|
|
46
|
+
else if (this.task.cronjob) {
|
|
47
|
+
allJobFinish = this.ExecuteTask_Cronjob(this.project, this.task, this.task_count);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
allJobFinish = this.ExecuteTask_Single(this.project, this.task, this.task_count);
|
|
51
|
+
}
|
|
52
|
+
if (allJobFinish) {
|
|
53
|
+
this.ExecuteTask_AllFinish(this.project, this.task);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
ExecuteTask_Cronjob(project, task, taskCount) {
|
|
57
|
+
let ns = this.get_idle_open();
|
|
58
|
+
let allJobFinish = false;
|
|
59
|
+
if (this.cron.length == 0) {
|
|
60
|
+
this.Init_CronContainer(taskCount);
|
|
61
|
+
this.target.messager_log(`[Execute] TaskCount: ${taskCount}`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const worker = this.cron.filter(x => x.uuid != '').map(x => x.uuid);
|
|
65
|
+
const counter = [];
|
|
66
|
+
worker.forEach(uuid => {
|
|
67
|
+
const index = counter.findIndex(x => x[0] == uuid);
|
|
68
|
+
if (index == -1)
|
|
69
|
+
counter.push([uuid, 1]);
|
|
70
|
+
else
|
|
71
|
+
counter[index][1] += 1;
|
|
72
|
+
});
|
|
73
|
+
const fullLoadUUID = counter.filter(x => x[1] >= this.multithread).map(x => x[0]);
|
|
74
|
+
ns = ns.filter(x => !fullLoadUUID.includes(x.uuid));
|
|
75
|
+
}
|
|
76
|
+
if (this.check_all_cron_end()) {
|
|
77
|
+
allJobFinish = true;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const needs = this.cron.filter(x => x.uuid == '' && x.work.filter(y => y.state != interface_1.ExecuteState.FINISH && y.state != interface_1.ExecuteState.ERROR).length > 0);
|
|
81
|
+
const min = Math.min(needs.length, ns.length);
|
|
82
|
+
for (let i = 0; i < min; i++) {
|
|
83
|
+
needs[i].uuid = ns[i].uuid;
|
|
84
|
+
}
|
|
85
|
+
const single = this.cron.filter(x => x.uuid != '');
|
|
86
|
+
for (var cronwork of single) {
|
|
87
|
+
const index = this.target.current_nodes.findIndex(x => x.uuid == cronwork.uuid);
|
|
88
|
+
if (index != -1) {
|
|
89
|
+
if (this.runners[cronwork.id] == undefined) {
|
|
90
|
+
this.runners[cronwork.id] = new region_subtask_1.Region_Subtask(this.target, cronwork, this.target.current_nodes[index]);
|
|
91
|
+
}
|
|
92
|
+
this.runners[cronwork.id]?.RUN();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return allJobFinish;
|
|
97
|
+
}
|
|
98
|
+
ExecuteTask_Single(project, task, taskCount) {
|
|
99
|
+
let allJobFinish = false;
|
|
100
|
+
let ns = [];
|
|
101
|
+
if (this.target.current_job.length > 0) {
|
|
102
|
+
const last = this.target.current_nodes.find(x => x.uuid == this.job[0].uuid);
|
|
103
|
+
if (last == undefined) {
|
|
104
|
+
ns = this.get_idle();
|
|
105
|
+
this.job = [];
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
ns = [last];
|
|
109
|
+
if (ns[0].websocket.readyState != 1) {
|
|
110
|
+
ns = this.get_idle();
|
|
111
|
+
this.job = [];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
17
114
|
}
|
|
115
|
+
else {
|
|
116
|
+
this.sync_local_para(this.target.localPara);
|
|
117
|
+
ns = this.get_idle();
|
|
118
|
+
if (ns.length > 0) {
|
|
119
|
+
this.target.proxy?.executeTaskStart([task, taskCount]);
|
|
120
|
+
this.target.proxy?.executeSubtaskStart([task, 0, ns[0].uuid]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (ns.length > 0 && ns[0].websocket.readyState == 1 && this.check_socket_state(ns[0]) != interface_1.ExecuteState.RUNNING) {
|
|
124
|
+
if (this.check_single_end()) {
|
|
125
|
+
allJobFinish = true;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (this.job.length != task.jobs.length) {
|
|
129
|
+
const job = JSON.parse(JSON.stringify(task.jobs[this.job.length]));
|
|
130
|
+
const runtime = (0, uuid_1.v6)();
|
|
131
|
+
this.job.push({
|
|
132
|
+
uuid: ns[0].uuid,
|
|
133
|
+
runtime: runtime,
|
|
134
|
+
state: interface_1.ExecuteState.RUNNING,
|
|
135
|
+
job: job
|
|
136
|
+
});
|
|
137
|
+
job.index = 0;
|
|
138
|
+
job.runtime_uuid = runtime;
|
|
139
|
+
const r = new region_job_1.Region_Job(this.target, task, job, ns[0]);
|
|
140
|
+
this.jrunners.push(r);
|
|
141
|
+
r.RUN();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return allJobFinish;
|
|
146
|
+
}
|
|
147
|
+
ExecuteTask_Setup(project, task, taskCount) {
|
|
148
|
+
let ns = this.get_idle_open();
|
|
149
|
+
let allJobFinish = false;
|
|
150
|
+
if (this.cron.length == 0) {
|
|
151
|
+
this.Init_CronContainer(taskCount);
|
|
152
|
+
this.target.messager_log(`[Execute] TaskCount: ${taskCount}`);
|
|
153
|
+
for (let i = 0; i < this.cron.length; i++) {
|
|
154
|
+
this.cron[i].uuid = this.target.current_nodes[i].uuid;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (this.check_all_cron_end()) {
|
|
158
|
+
allJobFinish = true;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const single = this.cron.filter(x => x.uuid != '');
|
|
162
|
+
for (var cronwork of single) {
|
|
163
|
+
const index = this.target.current_nodes.findIndex(x => x.uuid == cronwork.uuid);
|
|
164
|
+
if (index != -1) {
|
|
165
|
+
if (this.runners[cronwork.id] == undefined) {
|
|
166
|
+
this.runners[cronwork.id] = new region_subtask_1.Region_Subtask(this.target, cronwork, this.target.current_nodes[index]);
|
|
167
|
+
}
|
|
168
|
+
this.runners[cronwork.id]?.RUN();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return allJobFinish;
|
|
173
|
+
}
|
|
174
|
+
ExecuteTask_AllFinish(project, task) {
|
|
175
|
+
this.target.proxy?.executeTaskFinish(task);
|
|
176
|
+
this.target.messager_log(`[Execute] Task Finish ${task.uuid}`);
|
|
177
|
+
const index = project.tasks.findIndex(x => x.uuid == task.uuid);
|
|
178
|
+
if (index == project.tasks.length - 1) {
|
|
179
|
+
this.parent.runner = undefined;
|
|
180
|
+
this.target.t_state = interface_1.ExecuteState.FINISH;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
this.parent.runner = new Region_Task(this.target, project.tasks[index + 1]);
|
|
184
|
+
this.target.t_state = interface_1.ExecuteState.NONE;
|
|
185
|
+
}
|
|
186
|
+
this.job = [];
|
|
187
|
+
this.cron = [];
|
|
188
|
+
}
|
|
189
|
+
Init_CronContainer = (taskCount) => {
|
|
190
|
+
this.sync_local_para(this.target.localPara);
|
|
191
|
+
this.cron = [];
|
|
192
|
+
for (let i = 0; i < taskCount; i++) {
|
|
193
|
+
const d = {
|
|
194
|
+
id: i,
|
|
195
|
+
uuid: "",
|
|
196
|
+
work: this.task.jobs.map(x => ({
|
|
197
|
+
uuid: x.uuid,
|
|
198
|
+
runtime: '',
|
|
199
|
+
state: interface_1.ExecuteState.NONE,
|
|
200
|
+
job: x
|
|
201
|
+
}))
|
|
202
|
+
};
|
|
203
|
+
d.work.forEach((x, j) => x.runtime = (0, uuid_1.v6)({}, undefined, i * taskCount + j));
|
|
204
|
+
this.cron.push(d);
|
|
205
|
+
this.runners.push(undefined);
|
|
206
|
+
}
|
|
207
|
+
this.target.proxy?.executeTaskStart([this.task, taskCount]);
|
|
208
|
+
};
|
|
209
|
+
get_idle = () => {
|
|
210
|
+
return this.target.current_nodes.filter(x => this.check_socket_state(x) != interface_1.ExecuteState.RUNNING && x.websocket.readyState == 1);
|
|
211
|
+
};
|
|
212
|
+
check_socket_state = (target) => {
|
|
213
|
+
return target.current_job.length == 0 ? interface_1.ExecuteState.NONE : interface_1.ExecuteState.RUNNING;
|
|
214
|
+
};
|
|
215
|
+
sync_local_para = (target) => {
|
|
216
|
+
this.target.current_nodes.forEach(x => this.sync_para(target, x));
|
|
217
|
+
this.target.proxy?.updateDatabase(target);
|
|
218
|
+
};
|
|
219
|
+
sync_para = (target, source) => {
|
|
220
|
+
const h = {
|
|
221
|
+
name: 'set_database',
|
|
222
|
+
channel: this.target.uuid,
|
|
223
|
+
data: target
|
|
224
|
+
};
|
|
225
|
+
const h2 = {
|
|
226
|
+
name: 'set_libs',
|
|
227
|
+
channel: this.target.uuid,
|
|
228
|
+
data: this.target.libs
|
|
229
|
+
};
|
|
230
|
+
source.websocket.send(JSON.stringify(h));
|
|
231
|
+
source.websocket.send(JSON.stringify(h2));
|
|
232
|
+
};
|
|
233
|
+
get_idle_open = () => {
|
|
234
|
+
return this.target.current_nodes.filter(x => x.websocket.readyState == 1);
|
|
235
|
+
};
|
|
236
|
+
check_all_cron_end = () => {
|
|
237
|
+
return this.cron.filter(x => !this.check_cron_end(x)).length == 0;
|
|
238
|
+
};
|
|
239
|
+
check_cron_end = (cron) => {
|
|
240
|
+
return cron.work.filter(x => x.state == interface_1.ExecuteState.RUNNING || x.state == interface_1.ExecuteState.NONE).length == 0;
|
|
241
|
+
};
|
|
242
|
+
check_single_end = () => {
|
|
243
|
+
if (this.task == undefined)
|
|
244
|
+
return false;
|
|
245
|
+
return this.job.length == this.task.jobs.length &&
|
|
246
|
+
this.job.filter(y => y.state == interface_1.ExecuteState.RUNNING || y.state == interface_1.ExecuteState.NONE).length == 0;
|
|
247
|
+
};
|
|
248
|
+
get_task_multi_count = (t) => {
|
|
249
|
+
const r = this.get_number(t.multiKey);
|
|
250
|
+
return r == -1 ? 1 : r;
|
|
251
|
+
};
|
|
252
|
+
get_task_state_count(t) {
|
|
253
|
+
if (t.setupjob)
|
|
254
|
+
return this.target.current_nodes.length;
|
|
255
|
+
if (t.cronjob)
|
|
256
|
+
return this.get_number(t.cronjobKey);
|
|
257
|
+
else
|
|
258
|
+
return 1;
|
|
18
259
|
}
|
|
260
|
+
get_number(key) {
|
|
261
|
+
return this.get_number_global(key, this.target.localPara);
|
|
262
|
+
}
|
|
263
|
+
get_number_global(key, localPara) {
|
|
264
|
+
const e = this.database_update(localPara);
|
|
265
|
+
const a = e.replacePara(`%{${key}}%`);
|
|
266
|
+
return Number(a);
|
|
267
|
+
}
|
|
268
|
+
database_update = (localPara, n) => {
|
|
269
|
+
const e = new util_parser_1.Util_Parser([...util_parser_1.Util_Parser.to_keyvalue(localPara)]);
|
|
270
|
+
if (n != undefined) {
|
|
271
|
+
e.paras.push({ key: 'ck', value: n.toString() });
|
|
272
|
+
}
|
|
273
|
+
localPara.containers.forEach((c, index) => {
|
|
274
|
+
if (c.type != interface_1.DataType.Expression)
|
|
275
|
+
return;
|
|
276
|
+
c.value = e.replacePara(`%{${c.meta}}%`);
|
|
277
|
+
e.paras.find(p => p.key == c.name).value = c.value;
|
|
278
|
+
});
|
|
279
|
+
return e;
|
|
280
|
+
};
|
|
19
281
|
}
|
|
20
282
|
exports.Region_Task = Region_Task;
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import { Project
|
|
1
|
+
import { Project } from "../../interface";
|
|
2
2
|
import { ExecuteManager_Feedback } from "./feedback";
|
|
3
3
|
export declare class ExecuteManager_Runner extends ExecuteManager_Feedback {
|
|
4
|
-
protected ExecuteProject: (project: Project) => void;
|
|
5
|
-
private ExecuteTask;
|
|
6
|
-
private ExecuteTask_Cronjob;
|
|
7
|
-
private ExecuteTask_Single;
|
|
8
|
-
private ExecuteTask_Setup;
|
|
9
|
-
private ExecuteTask_AllFinish;
|
|
10
|
-
private ExecuteCronTask;
|
|
11
|
-
private ExecuteJob;
|
|
12
4
|
SyncDatabase: (p: Project) => void;
|
|
13
|
-
protected Init_CronContainer: (task: Task, taskCount: number) => void;
|
|
14
5
|
}
|
|
@@ -1,233 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExecuteManager_Runner = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
4
|
const interface_1 = require("../../interface");
|
|
6
5
|
const feedback_1 = require("./feedback");
|
|
7
6
|
const util_parser_1 = require("./util_parser");
|
|
8
7
|
class ExecuteManager_Runner extends feedback_1.ExecuteManager_Feedback {
|
|
9
|
-
ExecuteProject = (project) => {
|
|
10
|
-
if (this.current_t == undefined && project.task.length > 0 && this.t_state != interface_1.ExecuteState.FINISH) {
|
|
11
|
-
this.current_t = project.task[0];
|
|
12
|
-
this.messager_log(`[Execute] Task Start ${this.current_t.uuid}`);
|
|
13
|
-
this.messager_log(`[Execute] Task cron state: ${this.current_t.cronjob}`);
|
|
14
|
-
this.current_job = [];
|
|
15
|
-
this.current_cron = [];
|
|
16
|
-
}
|
|
17
|
-
else if (project.task.length == 0) {
|
|
18
|
-
this.current_t = undefined;
|
|
19
|
-
}
|
|
20
|
-
if (this.current_t != undefined) {
|
|
21
|
-
this.ExecuteTask(project, this.current_t);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const index = this.current_projects.findIndex(x => x.uuid == project.uuid);
|
|
25
|
-
if (index < this.current_projects.length - 1) {
|
|
26
|
-
this.messager_log(`[Execute] Project Finish ${this.current_p.uuid}`);
|
|
27
|
-
this.proxy?.executeProjectFinish([this.current_p, index]);
|
|
28
|
-
this.current_p = this.current_projects[index + 1];
|
|
29
|
-
this.proxy?.executeProjectStart([this.current_p, index + 1]);
|
|
30
|
-
this.t_state = interface_1.ExecuteState.NONE;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
this.messager_log(`[Execute] Project Finish ${this.current_p.uuid}`);
|
|
34
|
-
this.proxy?.executeProjectFinish([this.current_p, index]);
|
|
35
|
-
this.current_p = undefined;
|
|
36
|
-
this.state = interface_1.ExecuteState.FINISH;
|
|
37
|
-
this.t_state = interface_1.ExecuteState.NONE;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
ExecuteTask = (project, task) => {
|
|
42
|
-
if (this.t_state == interface_1.ExecuteState.NONE) {
|
|
43
|
-
this.t_state = interface_1.ExecuteState.RUNNING;
|
|
44
|
-
this.current_multithread = task.multi ? this.get_task_multi_count(task) : 1;
|
|
45
|
-
this.current_task_count = this.get_task_state_count(task);
|
|
46
|
-
}
|
|
47
|
-
let allJobFinish = false;
|
|
48
|
-
const hasJob = task.jobs.length > 0;
|
|
49
|
-
if (!hasJob) {
|
|
50
|
-
this.proxy?.executeTaskStart([task, this.current_task_count]);
|
|
51
|
-
this.proxy?.executeTaskFinish(task);
|
|
52
|
-
this.messager_log(`[Execute] Skip ! No job exists ${task.uuid}`);
|
|
53
|
-
this.ExecuteTask_AllFinish(project, task);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (task.setupjob) {
|
|
57
|
-
allJobFinish = this.ExecuteTask_Setup(project, task, this.current_task_count);
|
|
58
|
-
}
|
|
59
|
-
else if (task.cronjob) {
|
|
60
|
-
allJobFinish = this.ExecuteTask_Cronjob(project, task, this.current_task_count);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
allJobFinish = this.ExecuteTask_Single(project, task, this.current_task_count);
|
|
64
|
-
}
|
|
65
|
-
if (allJobFinish) {
|
|
66
|
-
this.ExecuteTask_AllFinish(project, task);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
ExecuteTask_Cronjob(project, task, taskCount) {
|
|
70
|
-
let ns = this.get_idle_open();
|
|
71
|
-
let allJobFinish = false;
|
|
72
|
-
if (this.current_cron.length == 0) {
|
|
73
|
-
this.Init_CronContainer(task, taskCount);
|
|
74
|
-
this.messager_log(`[Execute] TaskCount: ${taskCount}`);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
const worker = this.current_cron.filter(x => x.uuid != '').map(x => x.uuid);
|
|
78
|
-
const counter = [];
|
|
79
|
-
worker.forEach(uuid => {
|
|
80
|
-
const index = counter.findIndex(x => x[0] == uuid);
|
|
81
|
-
if (index == -1)
|
|
82
|
-
counter.push([uuid, 1]);
|
|
83
|
-
else
|
|
84
|
-
counter[index][1] += 1;
|
|
85
|
-
});
|
|
86
|
-
const fullLoadUUID = counter.filter(x => x[1] >= this.current_multithread).map(x => x[0]);
|
|
87
|
-
ns = ns.filter(x => !fullLoadUUID.includes(x.uuid));
|
|
88
|
-
}
|
|
89
|
-
if (this.check_all_cron_end()) {
|
|
90
|
-
allJobFinish = true;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
const needs = this.current_cron.filter(x => x.uuid == '' && x.work.filter(y => y.state != interface_1.ExecuteState.FINISH && y.state != interface_1.ExecuteState.ERROR).length > 0);
|
|
94
|
-
const min = Math.min(needs.length, ns.length);
|
|
95
|
-
for (let i = 0; i < min; i++) {
|
|
96
|
-
needs[i].uuid = ns[i].uuid;
|
|
97
|
-
}
|
|
98
|
-
const single = this.current_cron.filter(x => x.uuid != '');
|
|
99
|
-
for (var cronwork of single) {
|
|
100
|
-
const index = this.current_nodes.findIndex(x => x.uuid == cronwork.uuid);
|
|
101
|
-
if (index != -1) {
|
|
102
|
-
this.ExecuteCronTask(project, task, cronwork, this.current_nodes[index]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return allJobFinish;
|
|
107
|
-
}
|
|
108
|
-
ExecuteTask_Single(project, task, taskCount) {
|
|
109
|
-
let allJobFinish = false;
|
|
110
|
-
let ns = [];
|
|
111
|
-
if (this.current_job.length > 0) {
|
|
112
|
-
const last = this.current_nodes.find(x => x.uuid == this.current_job[0].uuid);
|
|
113
|
-
if (last == undefined) {
|
|
114
|
-
ns = this.get_idle();
|
|
115
|
-
this.current_job = [];
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
ns = [last];
|
|
119
|
-
if (ns[0].websocket.readyState != 1) {
|
|
120
|
-
ns = this.get_idle();
|
|
121
|
-
this.current_job = [];
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
this.sync_local_para(this.localPara);
|
|
127
|
-
ns = this.get_idle();
|
|
128
|
-
if (ns.length > 0) {
|
|
129
|
-
this.proxy?.executeTaskStart([task, taskCount]);
|
|
130
|
-
this.proxy?.executeSubtaskStart([task, 0, ns[0].uuid]);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (ns.length > 0 && ns[0].websocket.readyState == 1 && this.check_socket_state(ns[0]) != interface_1.ExecuteState.RUNNING) {
|
|
134
|
-
if (this.check_single_end()) {
|
|
135
|
-
allJobFinish = true;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
if (this.current_job.length != task.jobs.length) {
|
|
139
|
-
const job = JSON.parse(JSON.stringify(task.jobs[this.current_job.length]));
|
|
140
|
-
const runtime = (0, uuid_1.v6)();
|
|
141
|
-
this.current_job.push({
|
|
142
|
-
uuid: ns[0].uuid,
|
|
143
|
-
runtime: runtime,
|
|
144
|
-
state: interface_1.ExecuteState.RUNNING,
|
|
145
|
-
job: job
|
|
146
|
-
});
|
|
147
|
-
job.index = 0;
|
|
148
|
-
job.runtime_uuid = runtime;
|
|
149
|
-
this.ExecuteJob(project, task, job, ns[0], false);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return allJobFinish;
|
|
154
|
-
}
|
|
155
|
-
ExecuteTask_Setup(project, task, taskCount) {
|
|
156
|
-
let ns = this.get_idle_open();
|
|
157
|
-
let allJobFinish = false;
|
|
158
|
-
if (this.current_cron.length == 0) {
|
|
159
|
-
this.Init_CronContainer(task, taskCount);
|
|
160
|
-
this.messager_log(`[Execute] TaskCount: ${taskCount}`);
|
|
161
|
-
for (let i = 0; i < this.current_cron.length; i++) {
|
|
162
|
-
this.current_cron[i].uuid = this.current_nodes[i].uuid;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (this.check_all_cron_end()) {
|
|
166
|
-
allJobFinish = true;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const single = this.current_cron.filter(x => x.uuid != '');
|
|
170
|
-
for (var cronwork of single) {
|
|
171
|
-
const index = this.current_nodes.findIndex(x => x.uuid == cronwork.uuid);
|
|
172
|
-
if (index != -1) {
|
|
173
|
-
this.ExecuteCronTask(project, task, cronwork, this.current_nodes[index]);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return allJobFinish;
|
|
178
|
-
}
|
|
179
|
-
ExecuteTask_AllFinish(project, task) {
|
|
180
|
-
this.proxy?.executeTaskFinish(task);
|
|
181
|
-
this.messager_log(`[Execute] Task Finish ${task.uuid}`);
|
|
182
|
-
const index = project.task.findIndex(x => x.uuid == task.uuid);
|
|
183
|
-
if (index == project.task.length - 1) {
|
|
184
|
-
this.current_t = undefined;
|
|
185
|
-
this.t_state = interface_1.ExecuteState.FINISH;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
this.current_t = project.task[index + 1];
|
|
189
|
-
this.t_state = interface_1.ExecuteState.NONE;
|
|
190
|
-
}
|
|
191
|
-
this.current_job = [];
|
|
192
|
-
this.current_cron = [];
|
|
193
|
-
}
|
|
194
|
-
ExecuteCronTask = (project, task, work, ns) => {
|
|
195
|
-
if (ns.current_job.length < this.current_multithread) {
|
|
196
|
-
const rindex = work.work.findIndex(x => x.state == interface_1.ExecuteState.RUNNING);
|
|
197
|
-
if (rindex != -1)
|
|
198
|
-
return;
|
|
199
|
-
const index = work.work.findIndex(x => x.state == interface_1.ExecuteState.NONE);
|
|
200
|
-
if (index == 0)
|
|
201
|
-
this.proxy?.executeSubtaskStart([task, work.id, ns.uuid]);
|
|
202
|
-
if (index == -1)
|
|
203
|
-
return;
|
|
204
|
-
work.work[index].state = interface_1.ExecuteState.RUNNING;
|
|
205
|
-
try {
|
|
206
|
-
const job = JSON.parse(JSON.stringify(task.jobs[index]));
|
|
207
|
-
job.index = work.id;
|
|
208
|
-
job.runtime_uuid = work.work[index].runtime;
|
|
209
|
-
this.ExecuteJob(project, task, job, ns, true);
|
|
210
|
-
}
|
|
211
|
-
catch (err) {
|
|
212
|
-
this.messager_log(`[ExecuteCronTask Error] UUID: ${task.uuid}, Job count: ${task.jobs.length}, index: ${index}`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
ExecuteJob = (project, task, job, wss, iscron) => {
|
|
217
|
-
const n = job.index;
|
|
218
|
-
this.messager_log(`[Execute] Job Start ${n} ${job.uuid} ${wss.uuid}`);
|
|
219
|
-
this.proxy?.executeJobStart([job, n, wss.uuid]);
|
|
220
|
-
ExecuteManager_Runner.string_args_transform(task, job, this.messager_log, this.localPara, n);
|
|
221
|
-
const h = {
|
|
222
|
-
name: 'execute_job',
|
|
223
|
-
channel: this.uuid,
|
|
224
|
-
data: job
|
|
225
|
-
};
|
|
226
|
-
wss.current_job.push(job.runtime_uuid);
|
|
227
|
-
const stringdata = JSON.stringify(h);
|
|
228
|
-
wss.websocket.send(stringdata);
|
|
229
|
-
this.jobstack = this.jobstack + 1;
|
|
230
|
-
};
|
|
231
8
|
SyncDatabase = (p) => {
|
|
232
9
|
this.localPara = JSON.parse(JSON.stringify(p.database));
|
|
233
10
|
this.messager_log("[Execute] Sync Database !");
|
|
@@ -241,24 +18,5 @@ class ExecuteManager_Runner extends feedback_1.ExecuteManager_Feedback {
|
|
|
241
18
|
}
|
|
242
19
|
this.sync_local_para(this.localPara);
|
|
243
20
|
};
|
|
244
|
-
Init_CronContainer = (task, taskCount) => {
|
|
245
|
-
this.sync_local_para(this.localPara);
|
|
246
|
-
this.current_cron = [];
|
|
247
|
-
for (let i = 0; i < taskCount; i++) {
|
|
248
|
-
const d = {
|
|
249
|
-
id: i,
|
|
250
|
-
uuid: "",
|
|
251
|
-
work: task.jobs.map(x => ({
|
|
252
|
-
uuid: x.uuid,
|
|
253
|
-
runtime: '',
|
|
254
|
-
state: interface_1.ExecuteState.NONE,
|
|
255
|
-
job: x
|
|
256
|
-
}))
|
|
257
|
-
};
|
|
258
|
-
d.work.forEach((x, j) => x.runtime = (0, uuid_1.v6)({}, undefined, i * taskCount + j));
|
|
259
|
-
this.current_cron.push(d);
|
|
260
|
-
}
|
|
261
|
-
this.proxy?.executeTaskStart([task, taskCount]);
|
|
262
|
-
};
|
|
263
21
|
}
|
|
264
22
|
exports.ExecuteManager_Runner = ExecuteManager_Runner;
|