verteilen-core 1.2.4 → 1.2.7

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.
Files changed (142) hide show
  1. package/dist/client/analysis.d.ts +35 -0
  2. package/dist/client/analysis.js +382 -0
  3. package/dist/client/client.d.ts +25 -0
  4. package/dist/client/client.js +227 -0
  5. package/dist/client/cluster.d.ts +1 -0
  6. package/dist/{src/client → client}/cluster.js +1 -2
  7. package/dist/client/database.d.ts +13 -0
  8. package/dist/client/database.js +37 -0
  9. package/dist/client/execute.d.ts +24 -0
  10. package/dist/{src/client → client}/execute.js +61 -51
  11. package/dist/client/http.d.ts +7 -0
  12. package/dist/client/http.js +40 -0
  13. package/dist/client/javascript.d.ts +47 -0
  14. package/dist/{src/client → client}/javascript.js +110 -136
  15. package/dist/client/job_database.d.ts +10 -0
  16. package/dist/client/job_database.js +34 -0
  17. package/dist/client/job_execute.d.ts +20 -0
  18. package/dist/client/job_execute.js +173 -0
  19. package/dist/client/os.d.ts +29 -0
  20. package/dist/client/os.js +197 -0
  21. package/dist/client/resource.d.ts +7 -0
  22. package/dist/client/resource.js +107 -0
  23. package/dist/client/shell.d.ts +16 -0
  24. package/dist/client/shell.js +122 -0
  25. package/dist/computed.d.ts +13 -0
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.js +3 -3
  28. package/dist/interface/base.d.ts +70 -0
  29. package/dist/interface/bus.d.ts +90 -0
  30. package/dist/interface/enum.d.ts +143 -0
  31. package/dist/interface/execute.d.ts +20 -0
  32. package/dist/interface/record.d.ts +93 -0
  33. package/dist/interface/server.d.ts +76 -0
  34. package/dist/interface/struct.d.ts +182 -0
  35. package/dist/interface/table.d.ts +20 -0
  36. package/dist/interface/ui.d.ts +29 -0
  37. package/dist/interface.d.ts +29 -0
  38. package/dist/plugins/i18n.d.ts +1666 -0
  39. package/dist/script/console_manager.d.ts +18 -0
  40. package/dist/script/console_manager.js +131 -0
  41. package/dist/script/console_server_manager.d.ts +13 -0
  42. package/dist/script/console_server_manager.js +40 -0
  43. package/dist/script/execute/base.d.ts +45 -0
  44. package/dist/script/execute/base.js +200 -0
  45. package/dist/script/execute/feedback.d.ts +12 -0
  46. package/dist/script/execute/feedback.js +179 -0
  47. package/dist/script/execute/interface.d.ts +8 -0
  48. package/dist/script/execute/region_job.d.ts +5 -0
  49. package/dist/{src/script → script}/execute/region_job.js +1 -0
  50. package/dist/script/execute/region_project.d.ts +10 -0
  51. package/dist/{src/script → script}/execute/region_project.js +4 -0
  52. package/dist/script/execute/region_subtask.d.ts +5 -0
  53. package/dist/{src/script → script}/execute/region_subtask.js +1 -0
  54. package/dist/script/execute/region_task.d.ts +10 -0
  55. package/dist/{src/script → script}/execute/region_task.js +4 -0
  56. package/dist/script/execute/runner.d.ts +14 -0
  57. package/dist/script/execute/runner.js +264 -0
  58. package/dist/script/execute/util_parser.d.ts +14 -0
  59. package/dist/script/execute/util_parser.js +135 -0
  60. package/dist/script/execute_manager.d.ts +25 -0
  61. package/dist/script/execute_manager.js +297 -0
  62. package/dist/script/socket_manager.d.ts +31 -0
  63. package/dist/script/socket_manager.js +263 -0
  64. package/dist/script/webhook_manager.d.ts +3 -0
  65. package/dist/script/webhook_server_manager.d.ts +13 -0
  66. package/dist/script/webhook_server_manager.js +133 -0
  67. package/dist/server/detail.d.ts +72 -0
  68. package/dist/server/detail.js +451 -0
  69. package/dist/server/io.d.ts +46 -0
  70. package/dist/{src/server → server}/io.js +42 -51
  71. package/dist/server/plugin.d.ts +18 -0
  72. package/dist/{src/server → server}/plugin.js +45 -54
  73. package/dist/server/server.d.ts +27 -0
  74. package/dist/server/server.js +53 -0
  75. package/dist/server.d.ts +4 -0
  76. package/dist/util/console_handle.d.ts +20 -0
  77. package/dist/util/console_handle.js +244 -0
  78. package/dist/util/log_handle.d.ts +23 -0
  79. package/dist/util/log_handle.js +224 -0
  80. package/index.ts +1 -6
  81. package/package.json +1 -1
  82. package/src/index.ts +6 -0
  83. package/test/TEST.d.ts +1 -0
  84. package/test/TEST.js +88 -0
  85. package/test/client/execute.test.d.ts +1 -0
  86. package/{dist/test → test}/client/execute.test.js +6 -15
  87. package/test/client/javascript.test.d.ts +1 -0
  88. package/{dist/test → test}/client/javascript.test.js +21 -30
  89. package/test/client/server.test.d.ts +1 -0
  90. package/test/client/task.test.d.ts +1 -0
  91. package/{dist/test → test}/client/task.test.js +1 -1
  92. package/test/script/parser.test.d.ts +1 -0
  93. package/test/script/socket.test.d.ts +1 -0
  94. package/tsconfig.json +8 -4
  95. package/dist/jest.config.js +0 -8
  96. package/dist/src/client/analysis.js +0 -383
  97. package/dist/src/client/client.js +0 -233
  98. package/dist/src/client/database.js +0 -36
  99. package/dist/src/client/http.js +0 -37
  100. package/dist/src/client/job_database.js +0 -36
  101. package/dist/src/client/job_execute.js +0 -171
  102. package/dist/src/client/job_parameter.js +0 -36
  103. package/dist/src/client/os.js +0 -202
  104. package/dist/src/client/parameter.js +0 -36
  105. package/dist/src/client/resource.js +0 -118
  106. package/dist/src/client/shell.js +0 -118
  107. package/dist/src/script/console_manager.js +0 -125
  108. package/dist/src/script/console_server_manager.js +0 -37
  109. package/dist/src/script/execute/base.js +0 -197
  110. package/dist/src/script/execute/feedback.js +0 -188
  111. package/dist/src/script/execute/runner.js +0 -274
  112. package/dist/src/script/execute/util_parser.js +0 -137
  113. package/dist/src/script/execute_manager.js +0 -309
  114. package/dist/src/script/socket_manager.js +0 -260
  115. package/dist/src/script/webhook_server_manager.js +0 -140
  116. package/dist/src/server/detail.js +0 -428
  117. package/dist/src/server/server.js +0 -51
  118. package/dist/src/util/console_handle.js +0 -248
  119. package/dist/src/util/log_handle.js +0 -230
  120. package/dist/src/util/server/console_handle.js +0 -248
  121. package/dist/src/util/server/log_handle.js +0 -230
  122. package/dist/test/TEST.js +0 -105
  123. /package/dist/{src/computed.js → computed.js} +0 -0
  124. /package/dist/{src/interface → interface}/base.js +0 -0
  125. /package/dist/{src/interface → interface}/bus.js +0 -0
  126. /package/dist/{src/interface → interface}/enum.js +0 -0
  127. /package/dist/{src/interface → interface}/execute.js +0 -0
  128. /package/dist/{src/interface → interface}/record.js +0 -0
  129. /package/dist/{src/interface → interface}/server.js +0 -0
  130. /package/dist/{src/interface → interface}/struct.js +0 -0
  131. /package/dist/{src/interface → interface}/table.js +0 -0
  132. /package/dist/{src/interface → interface}/ui.js +0 -0
  133. /package/dist/{src/interface.js → interface.js} +0 -0
  134. /package/dist/{src/lan → lan}/en.json +0 -0
  135. /package/dist/{src/lan → lan}/zh_TW.json +0 -0
  136. /package/dist/{src/plugins → plugins}/i18n.js +0 -0
  137. /package/dist/{src/script → script}/execute/interface.js +0 -0
  138. /package/dist/{src/script → script}/webhook_manager.js +0 -0
  139. /package/dist/{src/server.js → server.js} +0 -0
  140. /package/{dist/test → test}/client/server.test.js +0 -0
  141. /package/{dist/test → test}/script/parser.test.js +0 -0
  142. /package/{dist/test → test}/script/socket.test.js +0 -0
@@ -1,197 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExecuteManager_Base = void 0;
4
- const uuid_1 = require("uuid");
5
- const interface_1 = require("../../interface");
6
- const util_parser_1 = require("./util_parser");
7
- class ExecuteManager_Base {
8
- constructor(_name, _websocket_manager, _messager_log, _record) {
9
- this.current_t = undefined;
10
- this.current_p = undefined;
11
- this.current_projects = [];
12
- this.current_nodes = [];
13
- this.current_cron = [];
14
- this.current_job = [];
15
- this.current_multithread = 1;
16
- this.current_task_count = -1;
17
- this.state = interface_1.ExecuteState.NONE;
18
- this.t_state = interface_1.ExecuteState.NONE;
19
- this.jobstack = 0;
20
- this.first = false;
21
- this.libs = undefined;
22
- this.proxy = undefined;
23
- this.localPara = undefined;
24
- this.sync_local_para = (target) => {
25
- var _a;
26
- this.current_nodes.forEach(x => this.sync_para(target, x));
27
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.updateDatabase(target);
28
- };
29
- this.sync_para = (target, source) => {
30
- const h = {
31
- name: 'set_database',
32
- channel: this.uuid,
33
- data: target
34
- };
35
- const h2 = {
36
- name: 'set_libs',
37
- channel: this.uuid,
38
- data: this.libs
39
- };
40
- source.websocket.send(JSON.stringify(h));
41
- source.websocket.send(JSON.stringify(h2));
42
- };
43
- this.release = (source) => {
44
- const h = {
45
- name: 'release',
46
- channel: this.uuid,
47
- data: 0
48
- };
49
- source.websocket.send(JSON.stringify(h));
50
- };
51
- this.check_all_cron_end = () => {
52
- return this.current_cron.filter(x => !this.check_cron_end(x)).length == 0;
53
- };
54
- this.check_cron_end = (cron) => {
55
- return cron.work.filter(x => x.state == interface_1.ExecuteState.RUNNING || x.state == interface_1.ExecuteState.NONE).length == 0;
56
- };
57
- this.check_single_end = () => {
58
- if (this.current_t == undefined)
59
- return false;
60
- return this.current_job.length == this.current_t.jobs.length &&
61
- this.current_job.filter(y => y.state == interface_1.ExecuteState.RUNNING || y.state == interface_1.ExecuteState.NONE).length == 0;
62
- };
63
- this.validation = (projects) => {
64
- if (this.websocket_manager.targets.length == 0) {
65
- this.messager_log(`[Execute State] The execute node does not exists`);
66
- return false;
67
- }
68
- projects.forEach(x => {
69
- x.task.forEach(t => {
70
- var _a, _b, _c, _d, _e, _f;
71
- if (t.cronjob) {
72
- const index = (_b = (_a = x.database) === null || _a === void 0 ? void 0 : _a.containers.findIndex(x => x.name == t.cronjobKey && x.type == interface_1.DataType.Number)) !== null && _b !== void 0 ? _b : -1;
73
- if (index == -1) {
74
- this.messager_log(`[Execute:CronJob] Project ${x.title} (${x.uuid}), Task ${t.title} (${t.uuid}), Has unknoed database: \"${t.cronjobKey}\"`);
75
- this.messager_log(`[Execute:CronJob] Cron task registerd key not found`);
76
- return false;
77
- }
78
- else if (((_c = x.database) === null || _c === void 0 ? void 0 : _c.containers[index].value) == 0) {
79
- this.messager_log(`[Execute:CronJob] Project ${x.title} (${x.uuid}), Task ${t.title} (${t.uuid}), Has unknoed database: \"${t.cronjobKey}\"`);
80
- this.messager_log(`[Execute:CronJob] Cron task value must bigger than 0`);
81
- return false;
82
- }
83
- }
84
- if (t.cronjob && t.multi) {
85
- const index = (_e = (_d = x.database) === null || _d === void 0 ? void 0 : _d.containers.findIndex(x => x.name == t.multiKey && x.type == interface_1.DataType.Number)) !== null && _e !== void 0 ? _e : -1;
86
- if (index == -1) {
87
- this.messager_log(`[Execute:Multi] Project ${x.title} (${x.uuid}), Task ${t.title} (${t.uuid}), Has unknoed database: \"${t.multiKey}\"`);
88
- this.messager_log(`[Execute:Multi] Cron task registerd key not found`);
89
- return false;
90
- }
91
- else if (((_f = x.database) === null || _f === void 0 ? void 0 : _f.containers[index].value) == 0) {
92
- this.messager_log(`[Execute:Multi] Project ${x.title} (${x.uuid}), Task ${t.title} (${t.uuid}), Has unknoed database: \"${t.multiKey}\"`);
93
- this.messager_log(`[Execute:Multi] Cron task value must bigger than 0`);
94
- return false;
95
- }
96
- }
97
- });
98
- });
99
- return true;
100
- };
101
- this.filter_lib = (projects, lib) => {
102
- const r = { libs: [] };
103
- projects.forEach(x => {
104
- x.task.forEach(y => {
105
- y.jobs.forEach(z => {
106
- let code = -1;
107
- if ((z.category == interface_1.JobCategory.Execution && z.type == interface_1.JobType.JAVASCRIPT) || (z.category == interface_1.JobCategory.Condition && z.type == interface_1.JobType2.JAVASCRIPT))
108
- code = 0;
109
- if (code == -1)
110
- return;
111
- z.string_args.forEach(s1 => {
112
- const target = lib.libs.find(l => l.name == s1);
113
- if (target != undefined)
114
- r.libs.push(target);
115
- });
116
- });
117
- });
118
- });
119
- return JSON.parse(JSON.stringify(r));
120
- };
121
- this.get_task_multi_count = (t) => {
122
- const r = this.get_number(t.multiKey);
123
- return r == -1 ? 1 : r;
124
- };
125
- this.removeDups = (arr) => {
126
- return [...new Set(arr)];
127
- };
128
- this.get_idle = () => {
129
- return this.current_nodes.filter(x => this.check_socket_state(x) != interface_1.ExecuteState.RUNNING && x.websocket.readyState == 1);
130
- };
131
- this.get_idle_open = () => {
132
- return this.current_nodes.filter(x => x.websocket.readyState == 1);
133
- };
134
- this.check_socket_state = (target) => {
135
- return target.current_job.length == 0 ? interface_1.ExecuteState.NONE : interface_1.ExecuteState.RUNNING;
136
- };
137
- this.name = _name;
138
- this.uuid = (0, uuid_1.v6)();
139
- this.record = _record;
140
- this.websocket_manager = _websocket_manager;
141
- this.messager_log = _messager_log;
142
- }
143
- get_task_state_count(t) {
144
- if (t.setupjob)
145
- return this.current_nodes.length;
146
- if (t.cronjob)
147
- return this.get_number(t.cronjobKey);
148
- else
149
- return 1;
150
- }
151
- get_number(key) {
152
- return ExecuteManager_Base.get_number_global(key, this.localPara);
153
- }
154
- static get_number_global(key, localPara) {
155
- const e = ExecuteManager_Base.database_update(localPara);
156
- const a = e.replacePara(`%{${key}}%`);
157
- return Number(a);
158
- }
159
- }
160
- exports.ExecuteManager_Base = ExecuteManager_Base;
161
- ExecuteManager_Base.string_args_transform = (task, job, messager_log, localPara, n) => {
162
- let e = ExecuteManager_Base.database_update(localPara, n);
163
- e = ExecuteManager_Base.property_update(task, e);
164
- for (let i = 0; i < job.string_args.length; i++) {
165
- const b = job.string_args[i];
166
- if (b == null || b == undefined || b.length == 0)
167
- continue;
168
- if (job.category == interface_1.JobCategory.Execution && job.type == interface_1.JobType.CREATE_FILE && i == 1)
169
- continue;
170
- job.string_args[i] = e.replacePara(job.string_args[i]);
171
- }
172
- };
173
- ExecuteManager_Base.property_update = (task, e) => {
174
- for (let j = 0; j < task.properties.length; j++) {
175
- const target = task.properties[j];
176
- const times = target.deep ? target.deep : 1;
177
- let act = target.expression;
178
- for (let k = 0; k < times; k++) {
179
- act = e.replacePara(`%{${act}}%`);
180
- }
181
- e.paras.push({ key: task.properties[j].name, value: act });
182
- }
183
- return e;
184
- };
185
- ExecuteManager_Base.database_update = (localPara, n) => {
186
- const e = new util_parser_1.Util_Parser([...util_parser_1.Util_Parser.to_keyvalue(localPara)]);
187
- if (n != undefined) {
188
- e.paras.push({ key: 'ck', value: n.toString() });
189
- }
190
- localPara.containers.forEach((c, index) => {
191
- if (c.type != interface_1.DataType.Expression)
192
- return;
193
- c.value = e.replacePara(`%{${c.meta}}%`);
194
- e.paras.find(p => p.key == c.name).value = c.value;
195
- });
196
- return e;
197
- };
@@ -1,188 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExecuteManager_Feedback = void 0;
4
- const interface_1 = require("../../interface");
5
- const base_1 = require("./base");
6
- class ExecuteManager_Feedback extends base_1.ExecuteManager_Base {
7
- constructor() {
8
- super(...arguments);
9
- this.Analysis = (d) => {
10
- const targetn = this.current_nodes.find(x => { var _a; return x.uuid == ((_a = d.c) === null || _a === void 0 ? void 0 : _a.uuid); });
11
- if (targetn == undefined) {
12
- this.messager_log("Not inside");
13
- return;
14
- }
15
- const typeMap = {
16
- 'feedback_message': this.feedback_message,
17
- 'feedback_job': this.feedback_job,
18
- 'feedback_string': this.feedback_string,
19
- 'feedback_boolean': this.feedback_boolean,
20
- 'feedback_number': this.feedback_number,
21
- 'feedback_object': this.feedback_object,
22
- };
23
- if (typeMap.hasOwnProperty(d.name)) {
24
- const castingFunc = typeMap[d.h.name];
25
- castingFunc(d.h.data, targetn, d.h.meta);
26
- }
27
- else {
28
- this.messager_log(`[Source Data Analysis] Decode failed, Unknowed header, name: ${d.name}, meta: ${d.h.meta}`);
29
- }
30
- };
31
- this.feedback_message = (data, source, meta) => {
32
- var _a;
33
- if (source == undefined) {
34
- this.messager_log("[Server Feedback Warn] source is none");
35
- return;
36
- }
37
- if (this.state == interface_1.ExecuteState.NONE) {
38
- this.messager_log("[Server Feedback Warn] state is none, should not received feedback");
39
- return;
40
- }
41
- this.messager_log(`[Execute] Single Received data: ${data.data}, cron length: ${this.current_cron.length}`);
42
- let index = 0;
43
- if (this.current_cron.length > 0 && meta != undefined) {
44
- const r = this.GetCronAndWork(meta, source);
45
- const cron = r[0];
46
- const work = r[1];
47
- if (cron != undefined && work != undefined) {
48
- index = cron.id;
49
- }
50
- }
51
- const d = {
52
- node_uuid: source.uuid,
53
- index: index,
54
- job_uuid: '',
55
- runtime_uuid: '',
56
- meta: 0,
57
- message: data.data
58
- };
59
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.feedbackMessage(d);
60
- };
61
- this.feedback_job = (data, source) => {
62
- var _a, _b, _c, _d, _e;
63
- if (source == undefined)
64
- return;
65
- if (this.state == interface_1.ExecuteState.NONE)
66
- return;
67
- this.jobstack = Math.max(this.jobstack - 1, 0);
68
- if (this.current_t == undefined) {
69
- console.error("Cannot feedback when task is null");
70
- return;
71
- }
72
- this.messager_log(`[Execute] Job Feedback: ${data.job_uuid} ${data.runtime_uuid} ${data.message} ${data.meta}`);
73
- if (this.current_job.length > 0) {
74
- const work = this.current_job.find(x => x.uuid == source.uuid && x.state == interface_1.ExecuteState.RUNNING);
75
- if (work == undefined) {
76
- console.error("Cannot find the feedback container, work", work);
77
- return;
78
- }
79
- data.index = 0;
80
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeJobFinish([work.job, 0, source.uuid, data.meta]);
81
- work.state = data.meta == 0 ? interface_1.ExecuteState.FINISH : interface_1.ExecuteState.ERROR;
82
- if (this.check_single_end()) {
83
- (_b = this.proxy) === null || _b === void 0 ? void 0 : _b.executeSubtaskFinish([this.current_t, 0, source.uuid]);
84
- this.messager_log(`[Execute] Subtask finish: ${this.current_t.uuid}`);
85
- }
86
- }
87
- else if (this.current_cron.length > 0) {
88
- const r = this.GetCronAndWork(data.runtime_uuid, source);
89
- const cron = r[0];
90
- const work = r[1];
91
- if (cron == undefined || work == undefined) {
92
- console.error("Cannot find the feedback container, cron or work", data.runtime_uuid, cron, work);
93
- console.error("Full current cron instance", this.current_cron);
94
- return;
95
- }
96
- (_c = this.proxy) === null || _c === void 0 ? void 0 : _c.executeJobFinish([work.job, cron.id, source.uuid, data.meta]);
97
- data.index = cron.id;
98
- work.state = data.meta == 0 ? interface_1.ExecuteState.FINISH : interface_1.ExecuteState.ERROR;
99
- if (this.check_cron_end(cron)) {
100
- (_d = this.proxy) === null || _d === void 0 ? void 0 : _d.executeSubtaskFinish([this.current_t, cron.id, cron.uuid]);
101
- this.messager_log(`[Execute] Subtask finish: ${this.current_t.uuid}`);
102
- cron.uuid = '';
103
- }
104
- }
105
- const index = source.current_job.findIndex(x => x == data.runtime_uuid);
106
- if (index == -1) {
107
- this.messager_log(`[Execute] Cannot find runtime uuid: ${data.runtime_uuid} in websocket pack source: ${source.uuid}`);
108
- }
109
- else {
110
- source.current_job.splice(index, 1);
111
- }
112
- data.node_uuid = source.uuid;
113
- (_e = this.proxy) === null || _e === void 0 ? void 0 : _e.feedbackMessage(data);
114
- };
115
- this.feedback_string = (data) => {
116
- var _a;
117
- if (this.current_p == undefined)
118
- return;
119
- const index = this.localPara.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.String);
120
- if (index != -1)
121
- this.localPara.containers[index].value = data.value;
122
- else
123
- this.localPara.containers.push({ name: data.key, value: data.value, type: interface_1.DataType.String, hidden: true, runtimeOnly: true });
124
- this.messager_log(`[String Feedback] ${data.key} = ${data.value}`);
125
- const d = { name: 'set_database', data: this.localPara };
126
- this.current_nodes.forEach(x => x.websocket.send(JSON.stringify(d)));
127
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.updateDatabase(this.localPara);
128
- };
129
- this.feedback_number = (data) => {
130
- var _a;
131
- if (this.current_p == undefined)
132
- return;
133
- const index = this.localPara.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.Number);
134
- if (index != -1)
135
- this.localPara.containers[index].value = data.value;
136
- else
137
- this.localPara.containers.push({ name: data.key, value: data.value, type: interface_1.DataType.Number, hidden: true, runtimeOnly: true });
138
- this.messager_log(`[Number Feedback] ${data.key} = ${data.value}`);
139
- const d = { name: 'set_database', data: this.localPara };
140
- this.current_nodes.forEach(x => x.websocket.send(JSON.stringify(d)));
141
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.updateDatabase(this.localPara);
142
- };
143
- this.feedback_object = (data) => {
144
- var _a;
145
- if (this.current_p == undefined)
146
- return;
147
- const index = this.localPara.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.Object);
148
- if (index != -1)
149
- this.localPara.containers[index].value = data.value;
150
- else
151
- this.localPara.containers.push({ name: data.key, value: data.value, type: interface_1.DataType.Object, hidden: true, runtimeOnly: true });
152
- this.messager_log(`[Object Feedback] ${data.key}`);
153
- const d = { name: 'set_database', data: this.localPara };
154
- this.current_nodes.forEach(x => x.websocket.send(JSON.stringify(d)));
155
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.updateDatabase(this.localPara);
156
- };
157
- this.feedback_boolean = (data) => {
158
- var _a;
159
- if (this.current_p == undefined)
160
- return;
161
- const index = this.localPara.containers.findIndex(x => x.name == data.key && x.type == interface_1.DataType.Boolean);
162
- if (index != -1)
163
- this.localPara.containers[index].value = data.value;
164
- else
165
- this.localPara.containers.push({ name: data.key, value: data.value, type: interface_1.DataType.Boolean, hidden: true, runtimeOnly: true });
166
- this.messager_log(`[Boolean Feedback] ${data.key} = ${data.value}`);
167
- const d = { name: 'set_database', data: this.localPara };
168
- this.current_nodes.forEach(x => x.websocket.send(JSON.stringify(d)));
169
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.updateDatabase(this.localPara);
170
- };
171
- this.GetCronAndWork = (runtime, source) => {
172
- let cron = undefined;
173
- let work = undefined;
174
- const crons = this.current_cron.filter(x => x.uuid == source.uuid);
175
- for (let i = 0; i < crons.length; i++) {
176
- const c = crons[i];
177
- const a = c.work.find(x => x.runtime == runtime);
178
- if (a != undefined) {
179
- cron = c;
180
- work = a;
181
- break;
182
- }
183
- }
184
- return [cron, work];
185
- };
186
- }
187
- }
188
- exports.ExecuteManager_Feedback = ExecuteManager_Feedback;
@@ -1,274 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExecuteManager_Runner = void 0;
4
- const uuid_1 = require("uuid");
5
- const interface_1 = require("../../interface");
6
- const feedback_1 = require("./feedback");
7
- const util_parser_1 = require("./util_parser");
8
- class ExecuteManager_Runner extends feedback_1.ExecuteManager_Feedback {
9
- constructor() {
10
- super(...arguments);
11
- this.ExecuteProject = (project) => {
12
- var _a, _b, _c;
13
- if (this.current_t == undefined && project.task.length > 0 && this.t_state != interface_1.ExecuteState.FINISH) {
14
- this.current_t = project.task[0];
15
- this.messager_log(`[Execute] Task Start ${this.current_t.uuid}`);
16
- this.messager_log(`[Execute] Task cron state: ${this.current_t.cronjob}`);
17
- this.current_job = [];
18
- this.current_cron = [];
19
- }
20
- else if (project.task.length == 0) {
21
- this.current_t = undefined;
22
- }
23
- if (this.current_t != undefined) {
24
- this.ExecuteTask(project, this.current_t);
25
- }
26
- else {
27
- const index = this.current_projects.findIndex(x => x.uuid == project.uuid);
28
- if (index < this.current_projects.length - 1) {
29
- this.messager_log(`[Execute] Project Finish ${this.current_p.uuid}`);
30
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeProjectFinish([this.current_p, index]);
31
- this.current_p = this.current_projects[index + 1];
32
- (_b = this.proxy) === null || _b === void 0 ? void 0 : _b.executeProjectStart([this.current_p, index + 1]);
33
- this.t_state = interface_1.ExecuteState.NONE;
34
- }
35
- else {
36
- this.messager_log(`[Execute] Project Finish ${this.current_p.uuid}`);
37
- (_c = this.proxy) === null || _c === void 0 ? void 0 : _c.executeProjectFinish([this.current_p, index]);
38
- this.current_p = undefined;
39
- this.state = interface_1.ExecuteState.FINISH;
40
- this.t_state = interface_1.ExecuteState.NONE;
41
- }
42
- }
43
- };
44
- this.ExecuteTask = (project, task) => {
45
- var _a, _b;
46
- if (this.t_state == interface_1.ExecuteState.NONE) {
47
- this.t_state = interface_1.ExecuteState.RUNNING;
48
- this.current_multithread = task.multi ? this.get_task_multi_count(task) : 1;
49
- this.current_task_count = this.get_task_state_count(task);
50
- }
51
- let allJobFinish = false;
52
- const hasJob = task.jobs.length > 0;
53
- if (!hasJob) {
54
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeTaskStart([task, this.current_task_count]);
55
- (_b = this.proxy) === null || _b === void 0 ? void 0 : _b.executeTaskFinish(task);
56
- this.messager_log(`[Execute] Skip ! No job exists ${task.uuid}`);
57
- this.ExecuteTask_AllFinish(project, task);
58
- return;
59
- }
60
- if (task.setupjob) {
61
- allJobFinish = this.ExecuteTask_Setup(project, task, this.current_task_count);
62
- }
63
- else if (task.cronjob) {
64
- allJobFinish = this.ExecuteTask_Cronjob(project, task, this.current_task_count);
65
- }
66
- else {
67
- allJobFinish = this.ExecuteTask_Single(project, task, this.current_task_count);
68
- }
69
- if (allJobFinish) {
70
- this.ExecuteTask_AllFinish(project, task);
71
- }
72
- };
73
- this.ExecuteCronTask = (project, task, work, ns) => {
74
- var _a;
75
- if (ns.current_job.length < this.current_multithread) {
76
- const rindex = work.work.findIndex(x => x.state == interface_1.ExecuteState.RUNNING);
77
- if (rindex != -1)
78
- return;
79
- const index = work.work.findIndex(x => x.state == interface_1.ExecuteState.NONE);
80
- if (index == 0)
81
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeSubtaskStart([task, work.id, ns.uuid]);
82
- if (index == -1)
83
- return;
84
- work.work[index].state = interface_1.ExecuteState.RUNNING;
85
- try {
86
- const job = JSON.parse(JSON.stringify(task.jobs[index]));
87
- job.index = work.id;
88
- job.runtime_uuid = work.work[index].runtime;
89
- this.ExecuteJob(project, task, job, ns, true);
90
- }
91
- catch (err) {
92
- this.messager_log(`[ExecuteCronTask Error] UUID: ${task.uuid}, Job count: ${task.jobs.length}, index: ${index}`);
93
- }
94
- }
95
- };
96
- this.ExecuteJob = (project, task, job, wss, iscron) => {
97
- var _a;
98
- const n = job.index;
99
- this.messager_log(`[Execute] Job Start ${n} ${job.uuid} ${wss.uuid}`);
100
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeJobStart([job, n, wss.uuid]);
101
- ExecuteManager_Runner.string_args_transform(task, job, this.messager_log, this.localPara, n);
102
- const h = {
103
- name: 'execute_job',
104
- channel: this.uuid,
105
- data: job
106
- };
107
- wss.current_job.push(job.runtime_uuid);
108
- const stringdata = JSON.stringify(h);
109
- wss.websocket.send(stringdata);
110
- this.jobstack = this.jobstack + 1;
111
- };
112
- this.SyncDatabase = (p) => {
113
- this.localPara = JSON.parse(JSON.stringify(p.database));
114
- this.messager_log("[Execute] Sync Database !");
115
- this.messager_log("[Execute] Generate local database object");
116
- for (let i = 0; i < this.localPara.containers.length; i++) {
117
- if (this.localPara.containers[i].type == interface_1.DataType.Expression && this.localPara.containers[i].meta != undefined) {
118
- const text = `%{${this.localPara.containers[i].meta}}%`;
119
- const e = new util_parser_1.Util_Parser([...util_parser_1.Util_Parser.to_keyvalue(this.localPara)]);
120
- this.localPara.containers[i].value = e.replacePara(text);
121
- }
122
- }
123
- this.sync_local_para(this.localPara);
124
- };
125
- this.Init_CronContainer = (task, taskCount) => {
126
- var _a;
127
- this.sync_local_para(this.localPara);
128
- this.current_cron = [];
129
- for (let i = 0; i < taskCount; i++) {
130
- const d = {
131
- id: i,
132
- uuid: "",
133
- work: task.jobs.map(x => ({
134
- uuid: x.uuid,
135
- runtime: '',
136
- state: interface_1.ExecuteState.NONE,
137
- job: x
138
- }))
139
- };
140
- d.work.forEach((x, j) => x.runtime = (0, uuid_1.v6)({}, undefined, i * taskCount + j));
141
- this.current_cron.push(d);
142
- }
143
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeTaskStart([task, taskCount]);
144
- };
145
- }
146
- ExecuteTask_Cronjob(project, task, taskCount) {
147
- let ns = this.get_idle_open();
148
- let allJobFinish = false;
149
- if (this.current_cron.length == 0) {
150
- this.Init_CronContainer(task, taskCount);
151
- this.messager_log(`[Execute] TaskCount: ${taskCount}`);
152
- }
153
- else {
154
- const worker = this.current_cron.filter(x => x.uuid != '').map(x => x.uuid);
155
- const counter = [];
156
- worker.forEach(uuid => {
157
- const index = counter.findIndex(x => x[0] == uuid);
158
- if (index == -1)
159
- counter.push([uuid, 1]);
160
- else
161
- counter[index][1] += 1;
162
- });
163
- const fullLoadUUID = counter.filter(x => x[1] >= this.current_multithread).map(x => x[0]);
164
- ns = ns.filter(x => !fullLoadUUID.includes(x.uuid));
165
- }
166
- if (this.check_all_cron_end()) {
167
- allJobFinish = true;
168
- }
169
- else {
170
- 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);
171
- const min = Math.min(needs.length, ns.length);
172
- for (let i = 0; i < min; i++) {
173
- needs[i].uuid = ns[i].uuid;
174
- }
175
- const single = this.current_cron.filter(x => x.uuid != '');
176
- for (var cronwork of single) {
177
- const index = this.current_nodes.findIndex(x => x.uuid == cronwork.uuid);
178
- if (index != -1) {
179
- this.ExecuteCronTask(project, task, cronwork, this.current_nodes[index]);
180
- }
181
- }
182
- }
183
- return allJobFinish;
184
- }
185
- ExecuteTask_Single(project, task, taskCount) {
186
- var _a, _b;
187
- let allJobFinish = false;
188
- let ns = [];
189
- if (this.current_job.length > 0) {
190
- const last = this.current_nodes.find(x => x.uuid == this.current_job[0].uuid);
191
- if (last == undefined) {
192
- ns = this.get_idle();
193
- this.current_job = [];
194
- }
195
- else {
196
- ns = [last];
197
- if (ns[0].websocket.readyState != 1) {
198
- ns = this.get_idle();
199
- this.current_job = [];
200
- }
201
- }
202
- }
203
- else {
204
- this.sync_local_para(this.localPara);
205
- ns = this.get_idle();
206
- if (ns.length > 0) {
207
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeTaskStart([task, taskCount]);
208
- (_b = this.proxy) === null || _b === void 0 ? void 0 : _b.executeSubtaskStart([task, 0, ns[0].uuid]);
209
- }
210
- }
211
- if (ns.length > 0 && ns[0].websocket.readyState == 1 && this.check_socket_state(ns[0]) != interface_1.ExecuteState.RUNNING) {
212
- if (this.check_single_end()) {
213
- allJobFinish = true;
214
- }
215
- else {
216
- if (this.current_job.length != task.jobs.length) {
217
- const job = JSON.parse(JSON.stringify(task.jobs[this.current_job.length]));
218
- const runtime = (0, uuid_1.v6)();
219
- this.current_job.push({
220
- uuid: ns[0].uuid,
221
- runtime: runtime,
222
- state: interface_1.ExecuteState.RUNNING,
223
- job: job
224
- });
225
- job.index = 0;
226
- job.runtime_uuid = runtime;
227
- this.ExecuteJob(project, task, job, ns[0], false);
228
- }
229
- }
230
- }
231
- return allJobFinish;
232
- }
233
- ExecuteTask_Setup(project, task, taskCount) {
234
- let ns = this.get_idle_open();
235
- let allJobFinish = false;
236
- if (this.current_cron.length == 0) {
237
- this.Init_CronContainer(task, taskCount);
238
- this.messager_log(`[Execute] TaskCount: ${taskCount}`);
239
- for (let i = 0; i < this.current_cron.length; i++) {
240
- this.current_cron[i].uuid = this.current_nodes[i].uuid;
241
- }
242
- }
243
- if (this.check_all_cron_end()) {
244
- allJobFinish = true;
245
- }
246
- else {
247
- const single = this.current_cron.filter(x => x.uuid != '');
248
- for (var cronwork of single) {
249
- const index = this.current_nodes.findIndex(x => x.uuid == cronwork.uuid);
250
- if (index != -1) {
251
- this.ExecuteCronTask(project, task, cronwork, this.current_nodes[index]);
252
- }
253
- }
254
- }
255
- return allJobFinish;
256
- }
257
- ExecuteTask_AllFinish(project, task) {
258
- var _a;
259
- (_a = this.proxy) === null || _a === void 0 ? void 0 : _a.executeTaskFinish(task);
260
- this.messager_log(`[Execute] Task Finish ${task.uuid}`);
261
- const index = project.task.findIndex(x => x.uuid == task.uuid);
262
- if (index == project.task.length - 1) {
263
- this.current_t = undefined;
264
- this.t_state = interface_1.ExecuteState.FINISH;
265
- }
266
- else {
267
- this.current_t = project.task[index + 1];
268
- this.t_state = interface_1.ExecuteState.NONE;
269
- }
270
- this.current_job = [];
271
- this.current_cron = [];
272
- }
273
- }
274
- exports.ExecuteManager_Runner = ExecuteManager_Runner;