ee-core 4.1.3 → 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,26 +1,26 @@
|
|
|
1
|
-
import EventEmitter = require("events");
|
|
2
|
-
import LoadBalancer = require("../load-balancer");
|
|
3
|
-
export declare class ChildPoolJob extends EventEmitter<[never]> {
|
|
4
|
-
constructor(opt?: {});
|
|
5
|
-
config: any;
|
|
6
|
-
boundMap: Map<any, any>;
|
|
7
|
-
children: {};
|
|
8
|
-
min: number;
|
|
9
|
-
max: number;
|
|
10
|
-
strategy: string;
|
|
11
|
-
weights: any[];
|
|
12
|
-
LB: LoadBalancer;
|
|
13
|
-
_initEvents(): void;
|
|
14
|
-
_removeChild(pid: any): void;
|
|
15
|
-
create(number?: number): Promise<string[]>;
|
|
16
|
-
_childCreated(childProcess: any): void;
|
|
17
|
-
run(filepath: any, params?: {}): any;
|
|
18
|
-
runPromise(filepath: any, params?: {}): Promise<any>;
|
|
19
|
-
getBoundChild(boundId: any): any;
|
|
20
|
-
getChildByPid(pid: any): any;
|
|
21
|
-
getChild(): any;
|
|
22
|
-
getPids(): string[];
|
|
23
|
-
// kill all
|
|
24
|
-
// type: sequence | parallel
|
|
25
|
-
killAll(type?: string): void;
|
|
26
|
-
}
|
|
1
|
+
import EventEmitter = require("events");
|
|
2
|
+
import LoadBalancer = require("../load-balancer");
|
|
3
|
+
export declare class ChildPoolJob extends EventEmitter<[never]> {
|
|
4
|
+
constructor(opt?: {});
|
|
5
|
+
config: any;
|
|
6
|
+
boundMap: Map<any, any>;
|
|
7
|
+
children: {};
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
strategy: string;
|
|
11
|
+
weights: any[];
|
|
12
|
+
LB: LoadBalancer;
|
|
13
|
+
_initEvents(): void;
|
|
14
|
+
_removeChild(pid: any): void;
|
|
15
|
+
create(number?: number): Promise<string[]>;
|
|
16
|
+
_childCreated(childProcess: any): void;
|
|
17
|
+
run(filepath: any, params?: {}): any;
|
|
18
|
+
runPromise(filepath: any, params?: {}): Promise<any>;
|
|
19
|
+
getBoundChild(boundId: any): any;
|
|
20
|
+
getChildByPid(pid: any): any;
|
|
21
|
+
getChild(): any;
|
|
22
|
+
getPids(): string[];
|
|
23
|
+
// kill all
|
|
24
|
+
// type: sequence | parallel
|
|
25
|
+
killAll(type?: string): void;
|
|
26
|
+
}
|
package/jobs/child-pool/index.js
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
const EventEmitter = require('events');
|
|
2
|
-
const LoadBalancer = require('../load-balancer');
|
|
3
|
-
const { getFullpath } = require('../../loader');
|
|
4
|
-
const { JobProcess } = require('../child/jobProcess');
|
|
5
|
-
const { Events } = require('../../const/channel');
|
|
6
|
-
const { validValue } = require('../../utils/helper');
|
|
7
|
-
const { getConfig } = require('../../config');
|
|
8
|
-
|
|
9
|
-
class ChildPoolJob extends EventEmitter {
|
|
10
|
-
|
|
11
|
-
constructor(opt = {}) {
|
|
12
|
-
super();
|
|
13
|
-
let options = Object.assign({
|
|
14
|
-
weights: [],
|
|
15
|
-
}, opt);
|
|
16
|
-
|
|
17
|
-
this.config = {};
|
|
18
|
-
this.boundMap = new Map();
|
|
19
|
-
this.children = {};
|
|
20
|
-
this.min = 3;
|
|
21
|
-
this.max = 6;
|
|
22
|
-
this.strategy = 'polling';
|
|
23
|
-
this.weights = new Array(this.max).fill().map((v, i) => {
|
|
24
|
-
let w = validValue(options.weights[i]) ? options.weights[i] : 1
|
|
25
|
-
return w;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
let lbOpt = {
|
|
29
|
-
algorithm: LoadBalancer.Algorithm.polling,
|
|
30
|
-
targets: [],
|
|
31
|
-
}
|
|
32
|
-
this.LB = new LoadBalancer(lbOpt);
|
|
33
|
-
|
|
34
|
-
const cfg = getConfig().jobs;
|
|
35
|
-
if (cfg) {
|
|
36
|
-
this.config = cfg;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this._initEvents();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
_initEvents() {
|
|
43
|
-
this.on(Events.childProcessExit, (data) => {
|
|
44
|
-
this._removeChild(data.pid);
|
|
45
|
-
});
|
|
46
|
-
this.on(Events.childProcessError, (data) => {
|
|
47
|
-
this._removeChild(data.pid);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_removeChild(pid) {
|
|
52
|
-
const length = Object.keys(this.children).length;
|
|
53
|
-
const lbOpt = {
|
|
54
|
-
id: pid,
|
|
55
|
-
weight: this.weights[length - 1],
|
|
56
|
-
}
|
|
57
|
-
this.LB.del(lbOpt);
|
|
58
|
-
delete this.children[pid];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async create(number = 3) {
|
|
62
|
-
if (number < 0 || number > this.max) {
|
|
63
|
-
throw new Error(`[ee-core] [jobs/child-pool] The number is invalid !`);
|
|
64
|
-
}
|
|
65
|
-
let currentNumber = this.children.length;
|
|
66
|
-
if (currentNumber > this.max) {
|
|
67
|
-
throw new Error(`[ee-core] [jobs/child-pool] The number of current processes number: ${currentNumber} is greater than the maximum: ${this.max} !`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (number + currentNumber > this.max) {
|
|
71
|
-
number = this.max - currentNumber;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// args
|
|
75
|
-
let options = Object.assign({
|
|
76
|
-
processArgs: {
|
|
77
|
-
type: 'childPoolJob'
|
|
78
|
-
}
|
|
79
|
-
}, {});
|
|
80
|
-
for (let i = 1; i <= number; i++) {
|
|
81
|
-
let task = new JobProcess(this, options);
|
|
82
|
-
this._childCreated(task);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let pids = Object.keys(this.children);
|
|
86
|
-
|
|
87
|
-
return pids;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Post creation processing of child processes
|
|
91
|
-
_childCreated(childProcess) {
|
|
92
|
-
let pid = childProcess.pid;
|
|
93
|
-
this.children[pid] = childProcess;
|
|
94
|
-
|
|
95
|
-
const length = Object.keys(this.children).length;
|
|
96
|
-
let lbTask = {
|
|
97
|
-
id: pid,
|
|
98
|
-
weight: this.weights[length - 1],
|
|
99
|
-
}
|
|
100
|
-
this.LB.add(lbTask);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Execute a job file
|
|
104
|
-
run(filepath, params = {}) {
|
|
105
|
-
const jobPath = getFullpath(filepath);
|
|
106
|
-
const childProcess = this.getChild();
|
|
107
|
-
childProcess.dispatch('run', jobPath, params);
|
|
108
|
-
|
|
109
|
-
return childProcess;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Asynchronous execution of a job file
|
|
113
|
-
async runPromise(filepath, params = {}) {
|
|
114
|
-
return this.run(filepath, params);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Get the bound process object
|
|
118
|
-
getBoundChild(boundId) {
|
|
119
|
-
let proc;
|
|
120
|
-
const boundPid = this.boundMap.get(boundId);
|
|
121
|
-
if (boundPid) {
|
|
122
|
-
proc = this.children[boundPid];
|
|
123
|
-
return proc;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 获取进程并绑定
|
|
127
|
-
proc = this.getChild();
|
|
128
|
-
this.boundMap.set(boundId, proc.pid);
|
|
129
|
-
|
|
130
|
-
return proc;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Retrieve a sub process object through PID
|
|
134
|
-
getChildByPid(pid) {
|
|
135
|
-
let proc = this.children[pid] || null;
|
|
136
|
-
return proc;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Get a sub process object
|
|
140
|
-
getChild() {
|
|
141
|
-
let proc;
|
|
142
|
-
const currentPids = Object.keys(this.children);
|
|
143
|
-
|
|
144
|
-
// 没有则创建
|
|
145
|
-
if (currentPids.length == 0) {
|
|
146
|
-
let subIds = this.create(1);
|
|
147
|
-
proc = this.children[subIds[0]];
|
|
148
|
-
} else {
|
|
149
|
-
// 从池子中获取一个
|
|
150
|
-
let onePid = this.LB.pickOne().id;
|
|
151
|
-
proc = this.children[onePid];
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!proc) {
|
|
155
|
-
let errorMessage = `[ee-core] [jobs/child-pool] Failed to obtain the child process !`
|
|
156
|
-
throw new Error(errorMessage);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return proc;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Get current pigs
|
|
163
|
-
getPids() {
|
|
164
|
-
let pids = Object.keys(this.children);
|
|
165
|
-
return pids;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// kill all
|
|
169
|
-
// type: sequence | parallel
|
|
170
|
-
killAll(type = 'parallel') {
|
|
171
|
-
let i = 1;
|
|
172
|
-
Object.keys(this.children).forEach(key => {
|
|
173
|
-
let proc = this.children[key];
|
|
174
|
-
if (proc) {
|
|
175
|
-
if (type == 'sequence') {
|
|
176
|
-
setTimeout(()=>{
|
|
177
|
-
proc.kill();
|
|
178
|
-
}, i * 1000)
|
|
179
|
-
i++;
|
|
180
|
-
} else {
|
|
181
|
-
proc.kill();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
module.exports = {
|
|
189
|
-
ChildPoolJob
|
|
190
|
-
};
|
|
1
|
+
const EventEmitter = require('events');
|
|
2
|
+
const LoadBalancer = require('../load-balancer');
|
|
3
|
+
const { getFullpath } = require('../../loader');
|
|
4
|
+
const { JobProcess } = require('../child/jobProcess');
|
|
5
|
+
const { Events } = require('../../const/channel');
|
|
6
|
+
const { validValue } = require('../../utils/helper');
|
|
7
|
+
const { getConfig } = require('../../config');
|
|
8
|
+
|
|
9
|
+
class ChildPoolJob extends EventEmitter {
|
|
10
|
+
|
|
11
|
+
constructor(opt = {}) {
|
|
12
|
+
super();
|
|
13
|
+
let options = Object.assign({
|
|
14
|
+
weights: [],
|
|
15
|
+
}, opt);
|
|
16
|
+
|
|
17
|
+
this.config = {};
|
|
18
|
+
this.boundMap = new Map();
|
|
19
|
+
this.children = {};
|
|
20
|
+
this.min = 3;
|
|
21
|
+
this.max = 6;
|
|
22
|
+
this.strategy = 'polling';
|
|
23
|
+
this.weights = new Array(this.max).fill().map((v, i) => {
|
|
24
|
+
let w = validValue(options.weights[i]) ? options.weights[i] : 1
|
|
25
|
+
return w;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
let lbOpt = {
|
|
29
|
+
algorithm: LoadBalancer.Algorithm.polling,
|
|
30
|
+
targets: [],
|
|
31
|
+
}
|
|
32
|
+
this.LB = new LoadBalancer(lbOpt);
|
|
33
|
+
|
|
34
|
+
const cfg = getConfig().jobs;
|
|
35
|
+
if (cfg) {
|
|
36
|
+
this.config = cfg;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this._initEvents();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_initEvents() {
|
|
43
|
+
this.on(Events.childProcessExit, (data) => {
|
|
44
|
+
this._removeChild(data.pid);
|
|
45
|
+
});
|
|
46
|
+
this.on(Events.childProcessError, (data) => {
|
|
47
|
+
this._removeChild(data.pid);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_removeChild(pid) {
|
|
52
|
+
const length = Object.keys(this.children).length;
|
|
53
|
+
const lbOpt = {
|
|
54
|
+
id: pid,
|
|
55
|
+
weight: this.weights[length - 1],
|
|
56
|
+
}
|
|
57
|
+
this.LB.del(lbOpt);
|
|
58
|
+
delete this.children[pid];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async create(number = 3) {
|
|
62
|
+
if (number < 0 || number > this.max) {
|
|
63
|
+
throw new Error(`[ee-core] [jobs/child-pool] The number is invalid !`);
|
|
64
|
+
}
|
|
65
|
+
let currentNumber = this.children.length;
|
|
66
|
+
if (currentNumber > this.max) {
|
|
67
|
+
throw new Error(`[ee-core] [jobs/child-pool] The number of current processes number: ${currentNumber} is greater than the maximum: ${this.max} !`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (number + currentNumber > this.max) {
|
|
71
|
+
number = this.max - currentNumber;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// args
|
|
75
|
+
let options = Object.assign({
|
|
76
|
+
processArgs: {
|
|
77
|
+
type: 'childPoolJob'
|
|
78
|
+
}
|
|
79
|
+
}, {});
|
|
80
|
+
for (let i = 1; i <= number; i++) {
|
|
81
|
+
let task = new JobProcess(this, options);
|
|
82
|
+
this._childCreated(task);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let pids = Object.keys(this.children);
|
|
86
|
+
|
|
87
|
+
return pids;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Post creation processing of child processes
|
|
91
|
+
_childCreated(childProcess) {
|
|
92
|
+
let pid = childProcess.pid;
|
|
93
|
+
this.children[pid] = childProcess;
|
|
94
|
+
|
|
95
|
+
const length = Object.keys(this.children).length;
|
|
96
|
+
let lbTask = {
|
|
97
|
+
id: pid,
|
|
98
|
+
weight: this.weights[length - 1],
|
|
99
|
+
}
|
|
100
|
+
this.LB.add(lbTask);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Execute a job file
|
|
104
|
+
run(filepath, params = {}) {
|
|
105
|
+
const jobPath = getFullpath(filepath);
|
|
106
|
+
const childProcess = this.getChild();
|
|
107
|
+
childProcess.dispatch('run', jobPath, params);
|
|
108
|
+
|
|
109
|
+
return childProcess;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Asynchronous execution of a job file
|
|
113
|
+
async runPromise(filepath, params = {}) {
|
|
114
|
+
return this.run(filepath, params);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Get the bound process object
|
|
118
|
+
getBoundChild(boundId) {
|
|
119
|
+
let proc;
|
|
120
|
+
const boundPid = this.boundMap.get(boundId);
|
|
121
|
+
if (boundPid) {
|
|
122
|
+
proc = this.children[boundPid];
|
|
123
|
+
return proc;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 获取进程并绑定
|
|
127
|
+
proc = this.getChild();
|
|
128
|
+
this.boundMap.set(boundId, proc.pid);
|
|
129
|
+
|
|
130
|
+
return proc;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Retrieve a sub process object through PID
|
|
134
|
+
getChildByPid(pid) {
|
|
135
|
+
let proc = this.children[pid] || null;
|
|
136
|
+
return proc;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Get a sub process object
|
|
140
|
+
getChild() {
|
|
141
|
+
let proc;
|
|
142
|
+
const currentPids = Object.keys(this.children);
|
|
143
|
+
|
|
144
|
+
// 没有则创建
|
|
145
|
+
if (currentPids.length == 0) {
|
|
146
|
+
let subIds = this.create(1);
|
|
147
|
+
proc = this.children[subIds[0]];
|
|
148
|
+
} else {
|
|
149
|
+
// 从池子中获取一个
|
|
150
|
+
let onePid = this.LB.pickOne().id;
|
|
151
|
+
proc = this.children[onePid];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!proc) {
|
|
155
|
+
let errorMessage = `[ee-core] [jobs/child-pool] Failed to obtain the child process !`
|
|
156
|
+
throw new Error(errorMessage);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return proc;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Get current pigs
|
|
163
|
+
getPids() {
|
|
164
|
+
let pids = Object.keys(this.children);
|
|
165
|
+
return pids;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// kill all
|
|
169
|
+
// type: sequence | parallel
|
|
170
|
+
killAll(type = 'parallel') {
|
|
171
|
+
let i = 1;
|
|
172
|
+
Object.keys(this.children).forEach(key => {
|
|
173
|
+
let proc = this.children[key];
|
|
174
|
+
if (proc) {
|
|
175
|
+
if (type == 'sequence') {
|
|
176
|
+
setTimeout(()=>{
|
|
177
|
+
proc.kill();
|
|
178
|
+
}, i * 1000)
|
|
179
|
+
i++;
|
|
180
|
+
} else {
|
|
181
|
+
proc.kill();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = {
|
|
189
|
+
ChildPoolJob
|
|
190
|
+
};
|
package/jobs/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ChildJob } from "./child";
|
|
2
|
-
import { ChildPoolJob } from "./child-pool";
|
|
3
|
-
export { ChildJob, ChildPoolJob };
|
|
1
|
+
import { ChildJob } from "./child";
|
|
2
|
+
import { ChildPoolJob } from "./child-pool";
|
|
3
|
+
export { ChildJob, ChildPoolJob };
|
package/jobs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const { ChildJob } = require('./child');
|
|
2
|
-
const { ChildPoolJob } = require('./child-pool');
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
ChildJob,
|
|
6
|
-
ChildPoolJob
|
|
1
|
+
const { ChildJob } = require('./child');
|
|
2
|
+
const { ChildPoolJob } = require('./child-pool');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
ChildJob,
|
|
6
|
+
ChildPoolJob
|
|
7
7
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _exports: {
|
|
2
|
-
[x: string]: (tasks: any, weightIndex: any, weightTotal: any, context: any) => any;
|
|
3
|
-
};
|
|
4
|
-
export = _exports;
|
|
1
|
+
declare const _exports: {
|
|
2
|
+
[x: string]: (tasks: any, weightIndex: any, weightTotal: any, context: any) => any;
|
|
3
|
+
};
|
|
4
|
+
export = _exports;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const Consts = require("../consts");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
[Consts.polling]: require('./polling'),
|
|
5
|
-
[Consts.weights]: require('./weights'),
|
|
6
|
-
[Consts.random]: require('./random'),
|
|
7
|
-
[Consts.specify]: require('./specify'),
|
|
8
|
-
[Consts.minimumConnection]: require('./minimumConnection'),
|
|
9
|
-
[Consts.weightsPolling]: require('./weightsPolling'),
|
|
10
|
-
[Consts.weightsRandom]: require('./weightsRandom'),
|
|
11
|
-
[Consts.weightsMinimumConnection]: require('./weightsMinimumConnection'),
|
|
1
|
+
const Consts = require("../consts");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
[Consts.polling]: require('./polling'),
|
|
5
|
+
[Consts.weights]: require('./weights'),
|
|
6
|
+
[Consts.random]: require('./random'),
|
|
7
|
+
[Consts.specify]: require('./specify'),
|
|
8
|
+
[Consts.minimumConnection]: require('./minimumConnection'),
|
|
9
|
+
[Consts.weightsPolling]: require('./weightsPolling'),
|
|
10
|
+
[Consts.weightsRandom]: require('./weightsRandom'),
|
|
11
|
+
[Consts.weightsMinimumConnection]: require('./weightsMinimumConnection'),
|
|
12
12
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function _exports(tasks: any, conMap?: {}): any;
|
|
2
|
-
export = _exports;
|
|
1
|
+
declare function _exports(tasks: any, conMap?: {}): any;
|
|
2
|
+
export = _exports;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 最小连接数
|
|
3
|
-
*/
|
|
4
|
-
module.exports = function (tasks, conMap={}) {
|
|
5
|
-
if (tasks.length < 2) return tasks[0] || null;
|
|
6
|
-
|
|
7
|
-
let min = conMap[tasks[0].id];
|
|
8
|
-
let minIndex = 0;
|
|
9
|
-
|
|
10
|
-
for (let i = 1; i < tasks.length; i++) {
|
|
11
|
-
const con = conMap[tasks[i].id] || 0;
|
|
12
|
-
if (con <= min) {
|
|
13
|
-
min = con;
|
|
14
|
-
minIndex = i;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return tasks[minIndex] || null;
|
|
1
|
+
/**
|
|
2
|
+
* 最小连接数
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (tasks, conMap={}) {
|
|
5
|
+
if (tasks.length < 2) return tasks[0] || null;
|
|
6
|
+
|
|
7
|
+
let min = conMap[tasks[0].id];
|
|
8
|
+
let minIndex = 0;
|
|
9
|
+
|
|
10
|
+
for (let i = 1; i < tasks.length; i++) {
|
|
11
|
+
const con = conMap[tasks[i].id] || 0;
|
|
12
|
+
if (con <= min) {
|
|
13
|
+
min = con;
|
|
14
|
+
minIndex = i;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return tasks[minIndex] || null;
|
|
19
19
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function _exports(tasks: any, currentIndex: any, context: any): any;
|
|
2
|
-
export = _exports;
|
|
1
|
+
declare function _exports(tasks: any, currentIndex: any, context: any): any;
|
|
2
|
+
export = _exports;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 轮询
|
|
3
|
-
*/
|
|
4
|
-
module.exports = function (tasks, currentIndex, context) {
|
|
5
|
-
if (!tasks.length) return null;
|
|
6
|
-
|
|
7
|
-
const task = tasks[currentIndex];
|
|
8
|
-
context.currentIndex ++;
|
|
9
|
-
context.currentIndex %= tasks.length;
|
|
10
|
-
|
|
11
|
-
return task || null;
|
|
1
|
+
/**
|
|
2
|
+
* 轮询
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (tasks, currentIndex, context) {
|
|
5
|
+
if (!tasks.length) return null;
|
|
6
|
+
|
|
7
|
+
const task = tasks[currentIndex];
|
|
8
|
+
context.currentIndex ++;
|
|
9
|
+
context.currentIndex %= tasks.length;
|
|
10
|
+
|
|
11
|
+
return task || null;
|
|
12
12
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function _exports(tasks: any): any;
|
|
2
|
-
export = _exports;
|
|
1
|
+
declare function _exports(tasks: any): any;
|
|
2
|
+
export = _exports;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 随机
|
|
3
|
-
*/
|
|
4
|
-
module.exports = function (tasks) {
|
|
5
|
-
|
|
6
|
-
const length = tasks.length;
|
|
7
|
-
const target = tasks[Math.floor(Math.random() * length)];
|
|
8
|
-
|
|
9
|
-
return target || null;
|
|
1
|
+
/**
|
|
2
|
+
* 随机
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (tasks) {
|
|
5
|
+
|
|
6
|
+
const length = tasks.length;
|
|
7
|
+
const target = tasks[Math.floor(Math.random() * length)];
|
|
8
|
+
|
|
9
|
+
return target || null;
|
|
10
10
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function _exports(tasks: any, id: any): any;
|
|
2
|
-
export = _exports;
|
|
1
|
+
declare function _exports(tasks: any, id: any): any;
|
|
2
|
+
export = _exports;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 声明绑定
|
|
3
|
-
*/
|
|
4
|
-
module.exports = function (tasks, id) {
|
|
5
|
-
let task;
|
|
6
|
-
|
|
7
|
-
for (let i = 0; i < tasks.length; i++) {
|
|
8
|
-
if (tasks[i].id === id) {
|
|
9
|
-
task = tasks[i];
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return task || null;
|
|
1
|
+
/**
|
|
2
|
+
* 声明绑定
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (tasks, id) {
|
|
5
|
+
let task;
|
|
6
|
+
|
|
7
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
8
|
+
if (tasks[i].id === id) {
|
|
9
|
+
task = tasks[i];
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return task || null;
|
|
15
15
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function _exports(tasks: any, weightTotal: any, context: any): any;
|
|
2
|
-
export = _exports;
|
|
1
|
+
declare function _exports(tasks: any, weightTotal: any, context: any): any;
|
|
2
|
+
export = _exports;
|