ee-core 4.1.2 → 4.1.4
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/LICENSE +21 -21
- package/README.md +65 -65
- package/app/application.d.ts +5 -5
- package/app/application.js +30 -30
- package/app/boot.d.ts +5 -5
- package/app/boot.js +80 -80
- package/app/dir.d.ts +1 -1
- package/app/dir.js +26 -26
- package/app/events.d.ts +14 -14
- package/app/events.js +55 -55
- package/app/index.d.ts +2 -2
- package/app/index.js +6 -6
- package/config/config_loader.d.ts +13 -13
- package/config/config_loader.js +65 -65
- package/config/default_config.d.ts +95 -95
- package/config/default_config.js +111 -111
- package/config/index.d.ts +28 -28
- package/config/index.js +24 -24
- package/const/channel.d.ts +16 -16
- package/const/channel.js +27 -27
- package/controller/controller_loader.d.ts +9 -9
- package/controller/controller_loader.js +77 -77
- package/controller/index.d.ts +2 -2
- package/controller/index.js +24 -24
- package/core/index.d.ts +2 -2
- package/core/index.js +11 -11
- package/core/loader/file_loader.d.ts +66 -66
- package/core/loader/file_loader.js +211 -211
- package/core/utils/index.d.ts +12 -12
- package/core/utils/index.js +83 -83
- package/core/utils/timing.d.ts +22 -22
- package/core/utils/timing.js +78 -78
- package/cross/cross.d.ts +19 -19
- package/cross/cross.js +151 -151
- package/cross/crossProcess.d.ts +29 -29
- package/cross/crossProcess.js +172 -172
- package/cross/index.d.ts +2 -2
- package/cross/index.js +8 -8
- package/electron/app/index.d.ts +5 -5
- package/electron/app/index.js +48 -48
- package/electron/index.d.ts +3 -3
- package/electron/index.js +15 -15
- package/electron/window/index.d.ts +6 -6
- package/electron/window/index.js +268 -268
- package/exception/index.d.ts +9 -9
- package/exception/index.js +100 -100
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.d.ts +1 -1
- package/html/index.js +10 -10
- package/index.d.ts +2 -2
- package/index.js +6 -6
- package/jobs/child/app.d.ts +1 -1
- package/jobs/child/app.js +69 -69
- package/jobs/child/index.d.ts +13 -13
- package/jobs/child/index.js +85 -85
- package/jobs/child/jobProcess.d.ts +16 -16
- package/jobs/child/jobProcess.js +133 -133
- package/jobs/child-pool/index.d.ts +26 -26
- package/jobs/child-pool/index.js +190 -190
- package/jobs/index.d.ts +3 -3
- package/jobs/index.js +6 -6
- package/jobs/load-balancer/algorithm/index.d.ts +4 -4
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -2
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -2
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.d.ts +2 -2
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -2
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.d.ts +8 -8
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.d.ts +96 -96
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.d.ts +16 -16
- package/jobs/load-balancer/scheduler.js +31 -31
- package/loader/index.d.ts +9 -9
- package/loader/index.js +99 -98
- package/log/index.d.ts +5 -5
- package/log/index.js +85 -85
- package/log/logger.d.ts +1 -1
- package/log/logger.js +94 -94
- package/message/childMessage.d.ts +10 -10
- package/message/childMessage.js +43 -43
- package/message/index.d.ts +3 -3
- package/message/index.js +9 -9
- package/package.json +42 -42
- package/ps/index.d.ts +39 -39
- package/ps/index.js +294 -294
- package/socket/httpServer.d.ts +8 -8
- package/socket/httpServer.js +199 -199
- package/socket/index.d.ts +10 -10
- package/socket/index.js +64 -64
- package/socket/ipcServer.d.ts +9 -9
- package/socket/ipcServer.js +105 -105
- package/socket/socketServer.d.ts +10 -10
- package/socket/socketServer.js +81 -81
- package/storage/index.d.ts +4 -4
- package/storage/index.js +6 -6
- package/storage/sqliteStorage.d.ts +16 -16
- package/storage/sqliteStorage.js +123 -123
- package/tsconfig.json +13 -13
- package/utils/extend.d.ts +2 -2
- package/utils/extend.js +77 -77
- package/utils/helper.d.ts +14 -14
- package/utils/helper.js +206 -206
- package/utils/index.d.ts +10 -10
- package/utils/index.js +167 -167
- package/utils/ip.d.ts +2 -2
- package/utils/ip.js +221 -221
- package/utils/is.d.ts +14 -14
- package/utils/is.js +111 -111
- package/utils/json.d.ts +5 -5
- package/utils/json.js +79 -79
- package/utils/pargv.d.ts +3 -3
- package/utils/pargv.js +267 -267
- package/utils/port/index.d.ts +1 -1
- package/utils/port/index.js +125 -125
- package/utils/wrap.d.ts +4 -4
- package/utils/wrap.js +40 -40
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
const Consts = require("./consts");
|
|
2
|
-
const Scheduler = require("./scheduler");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 负载均衡器
|
|
6
|
-
* @intro 参考electron-re项目,并做了一些改动
|
|
7
|
-
* @since 1.0.0
|
|
8
|
-
*/
|
|
9
|
-
class LoadBalancer {
|
|
10
|
-
|
|
11
|
-
static Algorithm = Consts;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {Object} options
|
|
15
|
-
* @param {Array } options.targets [ targets for load balancing calculation: [{id: 1, weight: 1}, {id: 2, weight: 2}] ]
|
|
16
|
-
* @param {String} options.algorithm
|
|
17
|
-
*/
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.targets = options.targets;
|
|
20
|
-
this.algorithm = options.algorithm || Consts.polling;
|
|
21
|
-
this.params = { // data for algorithm
|
|
22
|
-
currentIndex: 0, // index
|
|
23
|
-
weightIndex: 0, // index for weight alogrithm
|
|
24
|
-
weightTotal: 0, // total weight
|
|
25
|
-
connectionsMap: {}, // connections of each target
|
|
26
|
-
cpuOccupancyMap: {}, // cpu occupancy of each target
|
|
27
|
-
memoryOccupancyMap: {}, // cpu occupancy of each target
|
|
28
|
-
};
|
|
29
|
-
this.scheduler = new Scheduler(this.algorithm);
|
|
30
|
-
this.memoParams = this.memorizedParams();
|
|
31
|
-
this.calculateWeightIndex();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 算法参数
|
|
36
|
-
*/
|
|
37
|
-
memorizedParams() {
|
|
38
|
-
return {
|
|
39
|
-
[Consts.random]: () => [],
|
|
40
|
-
[Consts.polling]: () => [this.params.currentIndex, this.params],
|
|
41
|
-
[Consts.weights]: () => [this.params.weightTotal, this.params],
|
|
42
|
-
[Consts.specify]: (id) => [id],
|
|
43
|
-
[Consts.weightsRandom]: () => [this.params.weightTotal],
|
|
44
|
-
[Consts.weightsPolling]: () => [this.params.weightIndex, this.params.weightTotal, this.params],
|
|
45
|
-
[Consts.minimumConnection]: () => [this.params.connectionsMap],
|
|
46
|
-
[Consts.weightsMinimumConnection]: () => [this.params.weightTotal, this.params.connectionsMap, this.params],
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 刷新参数
|
|
52
|
-
*/
|
|
53
|
-
refreshParams(pidMap) {
|
|
54
|
-
const infos = Object.values(pidMap);
|
|
55
|
-
for (let info of infos) {
|
|
56
|
-
// this.params.connectionsMap[id] = connections;
|
|
57
|
-
this.params.cpuOccupancyMap[info.pid] = info.cpu;
|
|
58
|
-
this.params.memoryOccupancyMap[info.pid] = info.memory;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 选举出一个进程
|
|
64
|
-
*/
|
|
65
|
-
pickOne(...params) {
|
|
66
|
-
return this.scheduler.calculate(
|
|
67
|
-
this.targets, this.memoParams[this.algorithm](...params)
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 选举出多个进程
|
|
73
|
-
*/
|
|
74
|
-
pickMulti(count = 1, ...params) {
|
|
75
|
-
return new Array(count).fill().map(
|
|
76
|
-
() => this.pickOne(...params)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 计算权重
|
|
82
|
-
*/
|
|
83
|
-
calculateWeightIndex() {
|
|
84
|
-
this.params.weightTotal = this.targets.reduce((total, cur) => total + (cur.weight || 0), 0);
|
|
85
|
-
if (this.params.weightIndex > this.params.weightTotal) {
|
|
86
|
-
this.params.weightIndex = this.params.weightTotal;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 计算索引
|
|
92
|
-
*/
|
|
93
|
-
calculateIndex() {
|
|
94
|
-
if (this.params.currentIndex >= this.targets.length) {
|
|
95
|
-
this.params.currentIndex = (this.params.currentIndex - 1 >= 0) ? (this.params.currentIndex - 1) : 0;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 清除data
|
|
101
|
-
*/
|
|
102
|
-
clean(id) {
|
|
103
|
-
if (id) {
|
|
104
|
-
delete this.params.connectionsMap[id];
|
|
105
|
-
delete this.params.cpuOccupancyMap[id];
|
|
106
|
-
delete this.params.memoryOccupancyMap[id];
|
|
107
|
-
} else {
|
|
108
|
-
this.params = {
|
|
109
|
-
currentIndex: 0,
|
|
110
|
-
connectionsMap: {},
|
|
111
|
-
cpuOccupancyMap: {},
|
|
112
|
-
memoryOccupancyMap: {},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 添加一个进程信息
|
|
119
|
-
*/
|
|
120
|
-
add(task) {
|
|
121
|
-
if (this.targets.find(target => target.id === task.id)) {
|
|
122
|
-
return console.warn(`Add Operation: the task ${task.id} already exists.`);
|
|
123
|
-
}
|
|
124
|
-
this.targets.push(task);
|
|
125
|
-
this.calculateWeightIndex();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 删除一个进程信息
|
|
130
|
-
*/
|
|
131
|
-
del(target) {
|
|
132
|
-
let found = false;
|
|
133
|
-
for (let i = 0; i < this.targets.length; i++) {
|
|
134
|
-
if (this.targets[i].id === target.id) {
|
|
135
|
-
this.targets.splice(i, 1);
|
|
136
|
-
this.clean(target.id);
|
|
137
|
-
this.calculateIndex();
|
|
138
|
-
found = true;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (found) {
|
|
144
|
-
this.calculateWeightIndex();
|
|
145
|
-
} else {
|
|
146
|
-
console.warn(`Del Operation: the task ${target.id} is not found.`, this.targets);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* 擦除
|
|
152
|
-
*/
|
|
153
|
-
wipe() {
|
|
154
|
-
this.targets = [];
|
|
155
|
-
this.calculateWeightIndex();
|
|
156
|
-
this.clean();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* 更新计算参数
|
|
161
|
-
*/
|
|
162
|
-
updateParams(object) {
|
|
163
|
-
Object.entries(object).map(([key, value]) => {
|
|
164
|
-
if (key in this.params) {
|
|
165
|
-
this.params[key] = value;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 设置targets
|
|
172
|
-
*/
|
|
173
|
-
setTargets(targets) {
|
|
174
|
-
const targetsMap = targets.reduce((total, cur) => {
|
|
175
|
-
total[cur.id] = 1;
|
|
176
|
-
return total;
|
|
177
|
-
}, {});
|
|
178
|
-
this.targets.forEach(target => {
|
|
179
|
-
if (!(target.id in targetsMap)) {
|
|
180
|
-
this.clean(target.id);
|
|
181
|
-
this.calculateIndex();
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
this.targets = targets;
|
|
185
|
-
this.calculateWeightIndex();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* 设置算法
|
|
190
|
-
*/
|
|
191
|
-
setAlgorithm = (algorithm) => {
|
|
192
|
-
if (algorithm in Consts) {
|
|
193
|
-
this.algorithm = algorithm;
|
|
194
|
-
this.params.weightIndex = 0;
|
|
195
|
-
this.scheduler.setAlgorithm(this.algorithm);
|
|
196
|
-
} else {
|
|
197
|
-
throw new Error(`Invalid algorithm: ${algorithm}, pick from ${Object.keys(Consts).join('|')}`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
1
|
+
const Consts = require("./consts");
|
|
2
|
+
const Scheduler = require("./scheduler");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 负载均衡器
|
|
6
|
+
* @intro 参考electron-re项目,并做了一些改动
|
|
7
|
+
* @since 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
class LoadBalancer {
|
|
10
|
+
|
|
11
|
+
static Algorithm = Consts;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {Object} options
|
|
15
|
+
* @param {Array } options.targets [ targets for load balancing calculation: [{id: 1, weight: 1}, {id: 2, weight: 2}] ]
|
|
16
|
+
* @param {String} options.algorithm
|
|
17
|
+
*/
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.targets = options.targets;
|
|
20
|
+
this.algorithm = options.algorithm || Consts.polling;
|
|
21
|
+
this.params = { // data for algorithm
|
|
22
|
+
currentIndex: 0, // index
|
|
23
|
+
weightIndex: 0, // index for weight alogrithm
|
|
24
|
+
weightTotal: 0, // total weight
|
|
25
|
+
connectionsMap: {}, // connections of each target
|
|
26
|
+
cpuOccupancyMap: {}, // cpu occupancy of each target
|
|
27
|
+
memoryOccupancyMap: {}, // cpu occupancy of each target
|
|
28
|
+
};
|
|
29
|
+
this.scheduler = new Scheduler(this.algorithm);
|
|
30
|
+
this.memoParams = this.memorizedParams();
|
|
31
|
+
this.calculateWeightIndex();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 算法参数
|
|
36
|
+
*/
|
|
37
|
+
memorizedParams() {
|
|
38
|
+
return {
|
|
39
|
+
[Consts.random]: () => [],
|
|
40
|
+
[Consts.polling]: () => [this.params.currentIndex, this.params],
|
|
41
|
+
[Consts.weights]: () => [this.params.weightTotal, this.params],
|
|
42
|
+
[Consts.specify]: (id) => [id],
|
|
43
|
+
[Consts.weightsRandom]: () => [this.params.weightTotal],
|
|
44
|
+
[Consts.weightsPolling]: () => [this.params.weightIndex, this.params.weightTotal, this.params],
|
|
45
|
+
[Consts.minimumConnection]: () => [this.params.connectionsMap],
|
|
46
|
+
[Consts.weightsMinimumConnection]: () => [this.params.weightTotal, this.params.connectionsMap, this.params],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 刷新参数
|
|
52
|
+
*/
|
|
53
|
+
refreshParams(pidMap) {
|
|
54
|
+
const infos = Object.values(pidMap);
|
|
55
|
+
for (let info of infos) {
|
|
56
|
+
// this.params.connectionsMap[id] = connections;
|
|
57
|
+
this.params.cpuOccupancyMap[info.pid] = info.cpu;
|
|
58
|
+
this.params.memoryOccupancyMap[info.pid] = info.memory;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 选举出一个进程
|
|
64
|
+
*/
|
|
65
|
+
pickOne(...params) {
|
|
66
|
+
return this.scheduler.calculate(
|
|
67
|
+
this.targets, this.memoParams[this.algorithm](...params)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 选举出多个进程
|
|
73
|
+
*/
|
|
74
|
+
pickMulti(count = 1, ...params) {
|
|
75
|
+
return new Array(count).fill().map(
|
|
76
|
+
() => this.pickOne(...params)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 计算权重
|
|
82
|
+
*/
|
|
83
|
+
calculateWeightIndex() {
|
|
84
|
+
this.params.weightTotal = this.targets.reduce((total, cur) => total + (cur.weight || 0), 0);
|
|
85
|
+
if (this.params.weightIndex > this.params.weightTotal) {
|
|
86
|
+
this.params.weightIndex = this.params.weightTotal;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 计算索引
|
|
92
|
+
*/
|
|
93
|
+
calculateIndex() {
|
|
94
|
+
if (this.params.currentIndex >= this.targets.length) {
|
|
95
|
+
this.params.currentIndex = (this.params.currentIndex - 1 >= 0) ? (this.params.currentIndex - 1) : 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 清除data
|
|
101
|
+
*/
|
|
102
|
+
clean(id) {
|
|
103
|
+
if (id) {
|
|
104
|
+
delete this.params.connectionsMap[id];
|
|
105
|
+
delete this.params.cpuOccupancyMap[id];
|
|
106
|
+
delete this.params.memoryOccupancyMap[id];
|
|
107
|
+
} else {
|
|
108
|
+
this.params = {
|
|
109
|
+
currentIndex: 0,
|
|
110
|
+
connectionsMap: {},
|
|
111
|
+
cpuOccupancyMap: {},
|
|
112
|
+
memoryOccupancyMap: {},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 添加一个进程信息
|
|
119
|
+
*/
|
|
120
|
+
add(task) {
|
|
121
|
+
if (this.targets.find(target => target.id === task.id)) {
|
|
122
|
+
return console.warn(`Add Operation: the task ${task.id} already exists.`);
|
|
123
|
+
}
|
|
124
|
+
this.targets.push(task);
|
|
125
|
+
this.calculateWeightIndex();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 删除一个进程信息
|
|
130
|
+
*/
|
|
131
|
+
del(target) {
|
|
132
|
+
let found = false;
|
|
133
|
+
for (let i = 0; i < this.targets.length; i++) {
|
|
134
|
+
if (this.targets[i].id === target.id) {
|
|
135
|
+
this.targets.splice(i, 1);
|
|
136
|
+
this.clean(target.id);
|
|
137
|
+
this.calculateIndex();
|
|
138
|
+
found = true;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (found) {
|
|
144
|
+
this.calculateWeightIndex();
|
|
145
|
+
} else {
|
|
146
|
+
console.warn(`Del Operation: the task ${target.id} is not found.`, this.targets);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 擦除
|
|
152
|
+
*/
|
|
153
|
+
wipe() {
|
|
154
|
+
this.targets = [];
|
|
155
|
+
this.calculateWeightIndex();
|
|
156
|
+
this.clean();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 更新计算参数
|
|
161
|
+
*/
|
|
162
|
+
updateParams(object) {
|
|
163
|
+
Object.entries(object).map(([key, value]) => {
|
|
164
|
+
if (key in this.params) {
|
|
165
|
+
this.params[key] = value;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 设置targets
|
|
172
|
+
*/
|
|
173
|
+
setTargets(targets) {
|
|
174
|
+
const targetsMap = targets.reduce((total, cur) => {
|
|
175
|
+
total[cur.id] = 1;
|
|
176
|
+
return total;
|
|
177
|
+
}, {});
|
|
178
|
+
this.targets.forEach(target => {
|
|
179
|
+
if (!(target.id in targetsMap)) {
|
|
180
|
+
this.clean(target.id);
|
|
181
|
+
this.calculateIndex();
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
this.targets = targets;
|
|
185
|
+
this.calculateWeightIndex();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 设置算法
|
|
190
|
+
*/
|
|
191
|
+
setAlgorithm = (algorithm) => {
|
|
192
|
+
if (algorithm in Consts) {
|
|
193
|
+
this.algorithm = algorithm;
|
|
194
|
+
this.params.weightIndex = 0;
|
|
195
|
+
this.scheduler.setAlgorithm(this.algorithm);
|
|
196
|
+
} else {
|
|
197
|
+
throw new Error(`Invalid algorithm: ${algorithm}, pick from ${Object.keys(Consts).join('|')}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
202
|
module.exports = LoadBalancer;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export = Scheduler;
|
|
2
|
-
/**
|
|
3
|
-
* 算法调度器
|
|
4
|
-
*/
|
|
5
|
-
declare class Scheduler {
|
|
6
|
-
constructor(algorithm: any);
|
|
7
|
-
algorithm: any;
|
|
8
|
-
/**
|
|
9
|
-
* 计算
|
|
10
|
-
*/
|
|
11
|
-
calculate(tasks: any, params: any): any;
|
|
12
|
-
/**
|
|
13
|
-
* 设置算法
|
|
14
|
-
*/
|
|
15
|
-
setAlgorithm: (algorithm: any) => void;
|
|
16
|
-
}
|
|
1
|
+
export = Scheduler;
|
|
2
|
+
/**
|
|
3
|
+
* 算法调度器
|
|
4
|
+
*/
|
|
5
|
+
declare class Scheduler {
|
|
6
|
+
constructor(algorithm: any);
|
|
7
|
+
algorithm: any;
|
|
8
|
+
/**
|
|
9
|
+
* 计算
|
|
10
|
+
*/
|
|
11
|
+
calculate(tasks: any, params: any): any;
|
|
12
|
+
/**
|
|
13
|
+
* 设置算法
|
|
14
|
+
*/
|
|
15
|
+
setAlgorithm: (algorithm: any) => void;
|
|
16
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
const Consts = require("./consts");
|
|
2
|
-
const algorithm = require('./algorithm');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 算法调度器
|
|
6
|
-
*/
|
|
7
|
-
class Scheduler {
|
|
8
|
-
constructor(algorithm) {
|
|
9
|
-
this.algorithm = algorithm || Consts.polling;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 计算
|
|
14
|
-
*/
|
|
15
|
-
calculate(tasks, params) {
|
|
16
|
-
const results = algorithm[this.algorithm](tasks, ...params);
|
|
17
|
-
return results;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 设置算法
|
|
22
|
-
*/
|
|
23
|
-
setAlgorithm = (algorithm) => {
|
|
24
|
-
if (algorithm in Consts) {
|
|
25
|
-
this.algorithm = algorithm;
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error(`Invalid algorithm: ${algorithm}, pick from ${Object.keys(Consts).join('|')}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
1
|
+
const Consts = require("./consts");
|
|
2
|
+
const algorithm = require('./algorithm');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 算法调度器
|
|
6
|
+
*/
|
|
7
|
+
class Scheduler {
|
|
8
|
+
constructor(algorithm) {
|
|
9
|
+
this.algorithm = algorithm || Consts.polling;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 计算
|
|
14
|
+
*/
|
|
15
|
+
calculate(tasks, params) {
|
|
16
|
+
const results = algorithm[this.algorithm](tasks, ...params);
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 设置算法
|
|
22
|
+
*/
|
|
23
|
+
setAlgorithm = (algorithm) => {
|
|
24
|
+
if (algorithm in Consts) {
|
|
25
|
+
this.algorithm = algorithm;
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error(`Invalid algorithm: ${algorithm}, pick from ${Object.keys(Consts).join('|')}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
32
|
module.exports = Scheduler;
|
package/loader/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// 加载单个文件(如果是函数,将被执行)
|
|
2
|
-
export declare function loadFile(filepath: string, ...inject: any[]): any;
|
|
3
|
-
// 加载并运行文件
|
|
4
|
-
export declare function execFile(filepath: string, ...inject: any[]): Any;
|
|
5
|
-
export declare function requireFile(filepath: string): any;
|
|
6
|
-
// 模块的绝对路径
|
|
7
|
-
export declare function resolveModule(filepath: string): string;
|
|
8
|
-
// 获取electron目录下文件的绝对路径
|
|
9
|
-
export function getFullpath(filepath: string): string;
|
|
1
|
+
// 加载单个文件(如果是函数,将被执行)
|
|
2
|
+
export declare function loadFile(filepath: string, ...inject: any[]): any;
|
|
3
|
+
// 加载并运行文件
|
|
4
|
+
export declare function execFile(filepath: string, ...inject: any[]): Any;
|
|
5
|
+
export declare function requireFile(filepath: string): any;
|
|
6
|
+
// 模块的绝对路径
|
|
7
|
+
export declare function resolveModule(filepath: string): string;
|
|
8
|
+
// 获取electron目录下文件的绝对路径
|
|
9
|
+
export function getFullpath(filepath: string): string;
|