ee-core 2.12.0 → 4.0.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/app/application.d.ts +5 -0
- package/app/application.js +31 -0
- package/app/boot.d.ts +5 -0
- package/app/boot.js +74 -0
- package/app/dir.d.ts +1 -0
- package/app/dir.js +27 -0
- package/app/events.d.ts +14 -0
- package/app/events.js +56 -0
- package/app/index.d.ts +2 -0
- package/app/index.js +7 -0
- package/config/config_loader.d.ts +13 -0
- package/config/config_loader.js +19 -23
- package/config/default_config.d.ts +95 -0
- package/config/default_config.js +111 -0
- package/config/index.d.ts +28 -0
- package/config/index.js +20 -37
- package/const/channel.d.ts +16 -0
- package/const/channel.js +26 -16
- package/controller/controller_loader.d.ts +9 -0
- package/controller/controller_loader.js +78 -0
- package/controller/index.d.ts +2 -0
- package/controller/index.js +18 -19
- package/core/index.d.ts +2 -0
- package/core/index.js +6 -5
- package/core/loader/file_loader.d.ts +66 -0
- package/core/{lib/loader → loader}/file_loader.js +39 -156
- package/core/utils/index.d.ts +12 -0
- package/core/utils/index.js +83 -0
- package/core/utils/timing.d.ts +22 -0
- package/core/{lib/utils → utils}/timing.js +3 -2
- package/cross/cross.d.ts +19 -0
- package/cross/cross.js +152 -0
- package/cross/crossProcess.d.ts +29 -0
- package/cross/{spawnProcess.js → crossProcess.js} +36 -53
- package/cross/index.d.ts +2 -0
- package/cross/index.js +6 -181
- package/electron/app/index.d.ts +5 -0
- package/electron/app/index.js +38 -54
- package/electron/index.d.ts +3 -0
- package/electron/index.js +13 -17
- package/electron/window/index.d.ts +6 -0
- package/electron/window/index.js +260 -65
- package/exception/index.d.ts +9 -0
- package/exception/index.js +42 -54
- package/html/index.d.ts +1 -0
- package/html/index.js +7 -10
- package/index.d.ts +2 -0
- package/index.js +4 -52
- package/jobs/child/app.d.ts +1 -0
- package/jobs/child/app.js +10 -10
- package/jobs/child/index.d.ts +13 -0
- package/jobs/child/index.js +14 -11
- package/jobs/child/jobProcess.d.ts +16 -0
- package/jobs/child/{forkProcess.js → jobProcess.js} +31 -62
- package/jobs/child-pool/index.d.ts +26 -0
- package/jobs/child-pool/index.js +25 -48
- package/jobs/index.d.ts +3 -0
- package/jobs/index.js +2 -4
- package/jobs/load-balancer/algorithm/index.d.ts +4 -0
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/random.d.ts +2 -0
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
- package/jobs/load-balancer/consts.d.ts +8 -0
- package/jobs/load-balancer/index.d.ts +96 -0
- package/jobs/load-balancer/scheduler.d.ts +16 -0
- package/loader/index.d.ts +9 -0
- package/loader/index.js +73 -143
- package/log/index.d.ts +5 -0
- package/log/index.js +74 -57
- package/log/logger.d.ts +2 -0
- package/log/logger.js +75 -80
- package/message/childMessage.d.ts +10 -0
- package/message/childMessage.js +15 -25
- package/message/index.d.ts +3 -0
- package/message/index.js +7 -16
- package/package.json +8 -2
- package/ps/index.d.ts +37 -0
- package/ps/index.js +135 -238
- package/socket/httpServer.d.ts +8 -0
- package/socket/httpServer.js +55 -45
- package/socket/index.d.ts +10 -0
- package/socket/index.js +52 -69
- package/socket/ipcServer.d.ts +9 -0
- package/socket/ipcServer.js +87 -94
- package/socket/socketServer.d.ts +10 -0
- package/socket/socketServer.js +37 -25
- package/storage/index.d.ts +5 -0
- package/storage/index.js +5 -37
- package/storage/sqliteStorage.d.ts +16 -0
- package/storage/sqliteStorage.js +20 -20
- package/tsconfig.json +14 -0
- package/utils/extend.d.ts +2 -0
- package/utils/extend.js +10 -5
- package/utils/helper.d.ts +14 -0
- package/utils/helper.js +39 -53
- package/utils/index.d.ts +10 -0
- package/utils/index.js +47 -40
- package/utils/ip.d.ts +2 -0
- package/utils/ip.js +5 -45
- package/utils/is.d.ts +14 -0
- package/utils/is.js +107 -141
- package/utils/json.d.ts +5 -0
- package/utils/json.js +15 -7
- package/utils/pargv.d.ts +3 -0
- package/utils/pargv.js +5 -1
- package/utils/port/index.d.ts +1 -0
- package/utils/{get-port → port}/index.js +4 -26
- package/utils/wrap.d.ts +4 -0
- package/utils/wrap.js +8 -3
- package/addon/index.js +0 -35
- package/addon/window/index.js +0 -99
- package/bin/tools.js +0 -8
- package/config/cache.js +0 -62
- package/config/config.default.js +0 -331
- package/const/index.js +0 -9
- package/controller/baseContextClass.js +0 -25
- package/core/lib/ee.js +0 -216
- package/core/lib/loader/context_loader.js +0 -106
- package/core/lib/loader/ee_loader.js +0 -435
- package/core/lib/loader/mixin/addon.js +0 -32
- package/core/lib/loader/mixin/config.js +0 -130
- package/core/lib/loader/mixin/controller.js +0 -125
- package/core/lib/loader/mixin/service.js +0 -28
- package/core/lib/utils/base_context_class.js +0 -34
- package/core/lib/utils/function.js +0 -30
- package/core/lib/utils/index.js +0 -133
- package/core/lib/utils/sequencify.js +0 -59
- package/ee/appLoader.js +0 -48
- package/ee/application.js +0 -101
- package/ee/baseApp.js +0 -99
- package/ee/eeApp.js +0 -406
- package/ee/index.js +0 -58
- package/electron/window/winState.js +0 -186
- package/httpclient/index.js +0 -161
- package/jobs/baseJobClass.js +0 -16
- package/jobs/renderer/index.js +0 -141
- package/jobs/renderer/loadView.js +0 -41
- package/jobs/unification.js +0 -64
- package/main/index.js +0 -57
- package/old-utils/index.js +0 -91
- package/services/baseContextClass.js +0 -24
- package/services/index.js +0 -41
- package/socket/io.js +0 -28
- package/storage/jsondb/adapters/Base.js +0 -23
- package/storage/jsondb/adapters/FileSync.js +0 -64
- package/storage/jsondb/main.js +0 -55
- package/storage/jsondbStorage.js +0 -196
- package/utils/co.js +0 -237
- package/utils/copyto.js +0 -161
- package/utils/depd/index.js +0 -538
- package/utils/depd/lib/browser/index.js +0 -77
- package/utils/get-port/index.d.ts +0 -64
- package/utils/time/index.js +0 -20
- package/utils/time/ms.js +0 -162
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import EventEmitter = require("events");
|
|
2
|
+
import { JobProcess } from "./jobProcess";
|
|
3
|
+
export declare class ChildJob extends EventEmitter<[never]> {
|
|
4
|
+
constructor();
|
|
5
|
+
jobs: {};
|
|
6
|
+
config: any;
|
|
7
|
+
_initEvents(): void;
|
|
8
|
+
exec(filepath: string, params?: {}, opt?: {}): JobProcess;
|
|
9
|
+
createProcess(opt?: {}): JobProcess;
|
|
10
|
+
getPids(): string[];
|
|
11
|
+
execPromise(filepath: string, params?: {}, opt?: {}): Promise<JobProcess>;
|
|
12
|
+
}
|
|
13
|
+
|
package/jobs/child/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const EventEmitter = require('events');
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
2
|
+
const { JobProcess } = require('./jobProcess');
|
|
3
|
+
const { getFullpath } = require('../../loader');
|
|
4
|
+
const { Events } = require('../../const/channel');
|
|
5
|
+
const { getConfig } = require('../../config');
|
|
6
|
+
const { extend } = require('../../utils/extend');
|
|
6
7
|
|
|
7
8
|
class ChildJob extends EventEmitter {
|
|
8
9
|
|
|
@@ -11,7 +12,7 @@ class ChildJob extends EventEmitter {
|
|
|
11
12
|
this.jobs = {};
|
|
12
13
|
this.config = {};
|
|
13
14
|
|
|
14
|
-
const cfg =
|
|
15
|
+
const cfg = getConfig().jobs;
|
|
15
16
|
if (cfg) {
|
|
16
17
|
this.config = cfg;
|
|
17
18
|
}
|
|
@@ -23,10 +24,10 @@ class ChildJob extends EventEmitter {
|
|
|
23
24
|
* 初始化监听
|
|
24
25
|
*/
|
|
25
26
|
_initEvents() {
|
|
26
|
-
this.on(
|
|
27
|
+
this.on(Events.childProcessExit, (data) => {
|
|
27
28
|
delete this.jobs[data.pid];
|
|
28
29
|
});
|
|
29
|
-
this.on(
|
|
30
|
+
this.on(Events.childProcessError, (data) => {
|
|
30
31
|
delete this.jobs[data.pid];
|
|
31
32
|
});
|
|
32
33
|
}
|
|
@@ -35,7 +36,7 @@ class ChildJob extends EventEmitter {
|
|
|
35
36
|
* 执行一个job文件
|
|
36
37
|
*/
|
|
37
38
|
exec(filepath, params = {}, opt = {}) {
|
|
38
|
-
const jobPath =
|
|
39
|
+
const jobPath = getFullpath(filepath);
|
|
39
40
|
const proc = this.createProcess(opt);
|
|
40
41
|
const cmd = 'run';
|
|
41
42
|
proc.dispatch(cmd, jobPath, params);
|
|
@@ -47,12 +48,12 @@ class ChildJob extends EventEmitter {
|
|
|
47
48
|
* 创建子进程
|
|
48
49
|
*/
|
|
49
50
|
createProcess(opt = {}) {
|
|
50
|
-
|
|
51
|
+
const options = extend(true, {
|
|
51
52
|
processArgs: {
|
|
52
53
|
type: 'childJob'
|
|
53
54
|
}
|
|
54
55
|
}, opt);
|
|
55
|
-
const proc = new
|
|
56
|
+
const proc = new JobProcess(this, options);
|
|
56
57
|
if (!proc) {
|
|
57
58
|
let errorMessage = `[ee-core] [jobs/child] Failed to obtain the child process !`
|
|
58
59
|
throw new Error(errorMessage);
|
|
@@ -79,4 +80,6 @@ class ChildJob extends EventEmitter {
|
|
|
79
80
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
module.exports =
|
|
83
|
+
module.exports = {
|
|
84
|
+
ChildJob
|
|
85
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { ChildProcess } from "child_process";
|
|
3
|
+
declare export class JobProcess {
|
|
4
|
+
constructor(host: any, opt?: {});
|
|
5
|
+
emitter: EventEmitter<[never]>;
|
|
6
|
+
host: any;
|
|
7
|
+
args: string[];
|
|
8
|
+
sleeping: boolean;
|
|
9
|
+
child: ChildProcess;
|
|
10
|
+
pid: number;
|
|
11
|
+
_init(): void;
|
|
12
|
+
_eventEmit(m: any): void;
|
|
13
|
+
dispatch(cmd: string, jobPath?: string, ...params: any[]): void;
|
|
14
|
+
callFunc(jobPath?: string, funcName?: string, ...params: any[]): void;
|
|
15
|
+
kill(timeout?: number): void;
|
|
16
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const EventEmitter = require('events');
|
|
3
|
-
const { fork } = require('child_process');
|
|
4
3
|
const serialize = require('serialize-javascript');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const { fork } = require('child_process');
|
|
5
|
+
const { coreLogger } = require('../../log');
|
|
6
|
+
const { getBaseDir, isPackaged, allEnv } = require('../../ps');
|
|
7
|
+
const { Processes, Events, Receiver } = require('../../const/channel');
|
|
8
|
+
const { getRandomString } = require('../../utils/helper');
|
|
9
|
+
const { getFullpath } = require('../../loader');
|
|
10
|
+
const { extend } = require('../../utils/extend');
|
|
11
|
+
|
|
12
|
+
class JobProcess {
|
|
13
13
|
constructor(host, opt = {}) {
|
|
14
14
|
|
|
15
|
-
let cwd =
|
|
16
|
-
|
|
17
|
-
if (
|
|
15
|
+
let cwd = getBaseDir();
|
|
16
|
+
const appPath = path.join(__dirname, 'app.js');
|
|
17
|
+
if (isPackaged()) {
|
|
18
18
|
// todo fork的cwd目录为什么要在app.asar外 ?
|
|
19
|
-
cwd = path.join(
|
|
19
|
+
cwd = path.join(getBaseDir(), '..');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const options = extend(true, {
|
|
23
23
|
processArgs: {},
|
|
24
24
|
processOptions: {
|
|
25
25
|
cwd: cwd,
|
|
26
|
-
env:
|
|
26
|
+
env: allEnv(),
|
|
27
27
|
stdio: 'ignore' // pipe
|
|
28
28
|
}
|
|
29
29
|
}, opt);
|
|
@@ -41,22 +41,19 @@ class ForkProcess {
|
|
|
41
41
|
this._init();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* 初始化事件监听
|
|
46
|
-
*/
|
|
47
44
|
_init() {
|
|
48
45
|
const { messageLog } = this.host.config;
|
|
49
46
|
this.child.on('message', (m) => {
|
|
50
47
|
if (messageLog == true) {
|
|
51
|
-
|
|
48
|
+
coreLogger.info(`[ee-core] [jobs/child] received a message from child-process, message: ${serialize(m)}`);
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
if (m.channel ==
|
|
55
|
-
|
|
51
|
+
if (m.channel == Processes.showException) {
|
|
52
|
+
coreLogger.error(`${m.data}`);
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
// 收到子进程消息,转发到 event
|
|
59
|
-
if (m.channel ==
|
|
56
|
+
if (m.channel == Processes.sendToMain) {
|
|
60
57
|
this._eventEmit(m);
|
|
61
58
|
}
|
|
62
59
|
});
|
|
@@ -65,28 +62,25 @@ class ForkProcess {
|
|
|
65
62
|
let data = {
|
|
66
63
|
pid: this.pid
|
|
67
64
|
}
|
|
68
|
-
this.host.emit(
|
|
69
|
-
|
|
65
|
+
this.host.emit(Events.childProcessExit, data);
|
|
66
|
+
coreLogger.info(`[ee-core] [jobs/child] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
|
|
70
67
|
});
|
|
71
68
|
|
|
72
69
|
this.child.on('error', (err) => {
|
|
73
70
|
let data = {
|
|
74
71
|
pid: this.pid
|
|
75
72
|
}
|
|
76
|
-
this.host.emit(
|
|
77
|
-
|
|
73
|
+
this.host.emit(Events.childProcessError, data);
|
|
74
|
+
coreLogger.error(`[ee-core] [jobs/child] received a error from child-process, error: ${err}, pid:${this.pid}`);
|
|
78
75
|
});
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
/**
|
|
82
|
-
* event emit
|
|
83
|
-
*/
|
|
84
78
|
_eventEmit(m) {
|
|
85
79
|
switch (m.eventReceiver) {
|
|
86
|
-
case
|
|
80
|
+
case Receiver.forkProcess:
|
|
87
81
|
this.emitter.emit(m.event, m.data);
|
|
88
82
|
break;
|
|
89
|
-
case
|
|
83
|
+
case Receiver.childJob:
|
|
90
84
|
this.host.emit(m.event, m.data);
|
|
91
85
|
break;
|
|
92
86
|
default:
|
|
@@ -96,12 +90,9 @@ class ForkProcess {
|
|
|
96
90
|
}
|
|
97
91
|
}
|
|
98
92
|
|
|
99
|
-
/**
|
|
100
|
-
* 分发任务
|
|
101
|
-
*/
|
|
102
93
|
dispatch(cmd, jobPath = '', ...params) {
|
|
103
94
|
// 消息对象
|
|
104
|
-
const mid =
|
|
95
|
+
const mid = getRandomString();
|
|
105
96
|
let msg = {
|
|
106
97
|
mid,
|
|
107
98
|
cmd,
|
|
@@ -114,14 +105,11 @@ class ForkProcess {
|
|
|
114
105
|
this.child.send(msg);
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
/**
|
|
118
|
-
* 调用job的方法
|
|
119
|
-
*/
|
|
120
108
|
callFunc(jobPath = '', funcName = '', ...params) {
|
|
121
|
-
jobPath =
|
|
109
|
+
jobPath = getFullpath(jobPath);
|
|
122
110
|
|
|
123
111
|
// 消息对象
|
|
124
|
-
const mid =
|
|
112
|
+
const mid = getRandomString();
|
|
125
113
|
let msg = {
|
|
126
114
|
mid,
|
|
127
115
|
cmd:'run',
|
|
@@ -132,9 +120,6 @@ class ForkProcess {
|
|
|
132
120
|
this.child.send(msg);
|
|
133
121
|
}
|
|
134
122
|
|
|
135
|
-
/**
|
|
136
|
-
* kill
|
|
137
|
-
*/
|
|
138
123
|
kill(timeout = 1000) {
|
|
139
124
|
this.child.kill('SIGINT');
|
|
140
125
|
setTimeout(() => {
|
|
@@ -142,24 +127,8 @@ class ForkProcess {
|
|
|
142
127
|
this.child.kill('SIGKILL');
|
|
143
128
|
}, timeout)
|
|
144
129
|
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* sleep (仅Unix平台)
|
|
148
|
-
*/
|
|
149
|
-
sleep() {
|
|
150
|
-
if (this.sleeping) return;
|
|
151
|
-
process.kill(this.pid, 'SIGSTOP');
|
|
152
|
-
this.sleeping = true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* wakeup (仅Unix平台)
|
|
157
|
-
*/
|
|
158
|
-
wakeup() {
|
|
159
|
-
if (!this.sleeping) return;
|
|
160
|
-
process.kill(this.pid, 'SIGCONT');
|
|
161
|
-
this.sleeping = false;
|
|
162
|
-
}
|
|
163
130
|
}
|
|
164
131
|
|
|
165
|
-
module.exports =
|
|
132
|
+
module.exports = {
|
|
133
|
+
JobProcess
|
|
134
|
+
};
|
|
@@ -0,0 +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
|
+
}
|
package/jobs/child-pool/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const EventEmitter = require('events');
|
|
2
2
|
const LoadBalancer = require('../load-balancer');
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
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
8
|
|
|
9
9
|
class ChildPoolJob extends EventEmitter {
|
|
10
10
|
|
|
@@ -21,7 +21,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
21
21
|
this.max = 6;
|
|
22
22
|
this.strategy = 'polling';
|
|
23
23
|
this.weights = new Array(this.max).fill().map((v, i) => {
|
|
24
|
-
let w =
|
|
24
|
+
let w = validValue(options.weights[i]) ? options.weights[i] : 1
|
|
25
25
|
return w;
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
31
31
|
}
|
|
32
32
|
this.LB = new LoadBalancer(lbOpt);
|
|
33
33
|
|
|
34
|
-
const cfg =
|
|
34
|
+
const cfg = getConfig().jobs;
|
|
35
35
|
if (cfg) {
|
|
36
36
|
this.config = cfg;
|
|
37
37
|
}
|
|
@@ -39,21 +39,15 @@ class ChildPoolJob extends EventEmitter {
|
|
|
39
39
|
this._initEvents();
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* 初始化监听
|
|
44
|
-
*/
|
|
45
42
|
_initEvents() {
|
|
46
|
-
this.on(
|
|
43
|
+
this.on(Events.childProcessExit, (data) => {
|
|
47
44
|
this._removeChild(data.pid);
|
|
48
45
|
});
|
|
49
|
-
this.on(
|
|
46
|
+
this.on(Events.childProcessError, (data) => {
|
|
50
47
|
this._removeChild(data.pid);
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 移除对象
|
|
56
|
-
*/
|
|
50
|
+
|
|
57
51
|
_removeChild(pid) {
|
|
58
52
|
const length = Object.keys(this.children).length;
|
|
59
53
|
const lbOpt = {
|
|
@@ -63,10 +57,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
63
57
|
this.LB.del(lbOpt);
|
|
64
58
|
delete this.children[pid];
|
|
65
59
|
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 创建一个池子
|
|
69
|
-
*/
|
|
60
|
+
|
|
70
61
|
async create(number = 3) {
|
|
71
62
|
if (number < 0 || number > this.max) {
|
|
72
63
|
throw new Error(`[ee-core] [jobs/child-pool] The number is invalid !`);
|
|
@@ -87,7 +78,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
87
78
|
}
|
|
88
79
|
}, {});
|
|
89
80
|
for (let i = 1; i <= number; i++) {
|
|
90
|
-
let task = new
|
|
81
|
+
let task = new JobProcess(this, options);
|
|
91
82
|
this._childCreated(task);
|
|
92
83
|
}
|
|
93
84
|
|
|
@@ -96,9 +87,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
96
87
|
return pids;
|
|
97
88
|
}
|
|
98
89
|
|
|
99
|
-
|
|
100
|
-
* 子进程创建后处理
|
|
101
|
-
*/
|
|
90
|
+
// Post creation processing of child processes
|
|
102
91
|
_childCreated(childProcess) {
|
|
103
92
|
let pid = childProcess.pid;
|
|
104
93
|
this.children[pid] = childProcess;
|
|
@@ -111,27 +100,21 @@ class ChildPoolJob extends EventEmitter {
|
|
|
111
100
|
this.LB.add(lbTask);
|
|
112
101
|
}
|
|
113
102
|
|
|
114
|
-
|
|
115
|
-
* 执行一个job文件
|
|
116
|
-
*/
|
|
103
|
+
// Execute a job file
|
|
117
104
|
run(filepath, params = {}) {
|
|
118
|
-
const jobPath =
|
|
105
|
+
const jobPath = getFullpath(filepath);
|
|
119
106
|
const childProcess = this.getChild();
|
|
120
107
|
childProcess.dispatch('run', jobPath, params);
|
|
121
108
|
|
|
122
109
|
return childProcess;
|
|
123
110
|
}
|
|
124
111
|
|
|
125
|
-
|
|
126
|
-
* 异步执行一个job文件
|
|
127
|
-
*/
|
|
112
|
+
// Asynchronous execution of a job file
|
|
128
113
|
async runPromise(filepath, params = {}) {
|
|
129
114
|
return this.run(filepath, params);
|
|
130
115
|
}
|
|
131
116
|
|
|
132
|
-
|
|
133
|
-
* 获取绑定的进程对象
|
|
134
|
-
*/
|
|
117
|
+
// Get the bound process object
|
|
135
118
|
getBoundChild(boundId) {
|
|
136
119
|
let proc;
|
|
137
120
|
const boundPid = this.boundMap.get(boundId);
|
|
@@ -147,17 +130,13 @@ class ChildPoolJob extends EventEmitter {
|
|
|
147
130
|
return proc;
|
|
148
131
|
}
|
|
149
132
|
|
|
150
|
-
|
|
151
|
-
* 通过pid获取一个子进程对象
|
|
152
|
-
*/
|
|
133
|
+
// Retrieve a sub process object through PID
|
|
153
134
|
getChildByPid(pid) {
|
|
154
135
|
let proc = this.children[pid] || null;
|
|
155
136
|
return proc;
|
|
156
137
|
}
|
|
157
138
|
|
|
158
|
-
|
|
159
|
-
* 获取一个子进程对象
|
|
160
|
-
*/
|
|
139
|
+
// Get a sub process object
|
|
161
140
|
getChild() {
|
|
162
141
|
let proc;
|
|
163
142
|
const currentPids = Object.keys(this.children);
|
|
@@ -180,18 +159,14 @@ class ChildPoolJob extends EventEmitter {
|
|
|
180
159
|
return proc;
|
|
181
160
|
}
|
|
182
161
|
|
|
183
|
-
|
|
184
|
-
* 获取当前pids
|
|
185
|
-
*/
|
|
162
|
+
// Get current pigs
|
|
186
163
|
getPids() {
|
|
187
164
|
let pids = Object.keys(this.children);
|
|
188
165
|
return pids;
|
|
189
166
|
}
|
|
190
167
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
* @param type {String} - 'sequence' | 'parallel'
|
|
194
|
-
*/
|
|
168
|
+
// kill all
|
|
169
|
+
// type: sequence | parallel
|
|
195
170
|
killAll(type = 'parallel') {
|
|
196
171
|
let i = 1;
|
|
197
172
|
Object.keys(this.children).forEach(key => {
|
|
@@ -210,4 +185,6 @@ class ChildPoolJob extends EventEmitter {
|
|
|
210
185
|
}
|
|
211
186
|
}
|
|
212
187
|
|
|
213
|
-
module.exports =
|
|
188
|
+
module.exports = {
|
|
189
|
+
ChildPoolJob
|
|
190
|
+
};
|
package/jobs/index.d.ts
ADDED
package/jobs/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
const ChildJob = require('./child');
|
|
2
|
-
const
|
|
3
|
-
const ChildPoolJob = require('./child-pool');
|
|
1
|
+
const { ChildJob } = require('./child');
|
|
2
|
+
const { ChildPoolJob } = require('./child-pool');
|
|
4
3
|
|
|
5
4
|
module.exports = {
|
|
6
5
|
ChildJob,
|
|
7
|
-
RendererJob,
|
|
8
6
|
ChildPoolJob
|
|
9
7
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare let polling: string;
|
|
2
|
+
export declare let weights: string;
|
|
3
|
+
export declare let random: string;
|
|
4
|
+
export declare let specify: string;
|
|
5
|
+
export declare let weightsPolling: string;
|
|
6
|
+
export declare let weightsRandom: string;
|
|
7
|
+
export declare let minimumConnection: string;
|
|
8
|
+
export declare let weightsMinimumConnection: string;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export = LoadBalancer;
|
|
2
|
+
/**
|
|
3
|
+
* 负载均衡器
|
|
4
|
+
* @intro 参考electron-re项目,并做了一些改动
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
declare class LoadBalancer {
|
|
8
|
+
static Algorithm: {
|
|
9
|
+
polling: string;
|
|
10
|
+
weights: string;
|
|
11
|
+
random: string;
|
|
12
|
+
specify: string;
|
|
13
|
+
weightsPolling: string;
|
|
14
|
+
weightsRandom: string;
|
|
15
|
+
minimumConnection: string;
|
|
16
|
+
weightsMinimumConnection: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @param {Object} options
|
|
20
|
+
* @param {Array } options.targets [ targets for load balancing calculation: [{id: 1, weight: 1}, {id: 2, weight: 2}] ]
|
|
21
|
+
* @param {String} options.algorithm
|
|
22
|
+
*/
|
|
23
|
+
constructor(options: {
|
|
24
|
+
targets: any[];
|
|
25
|
+
algorithm: string;
|
|
26
|
+
});
|
|
27
|
+
targets: any[];
|
|
28
|
+
algorithm: string;
|
|
29
|
+
params: {
|
|
30
|
+
currentIndex: number;
|
|
31
|
+
weightIndex: number;
|
|
32
|
+
weightTotal: number;
|
|
33
|
+
connectionsMap: {};
|
|
34
|
+
cpuOccupancyMap: {};
|
|
35
|
+
memoryOccupancyMap: {};
|
|
36
|
+
};
|
|
37
|
+
scheduler: Scheduler;
|
|
38
|
+
memoParams: {
|
|
39
|
+
[x: string]: (id: any) => any[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* 算法参数
|
|
43
|
+
*/
|
|
44
|
+
memorizedParams(): {
|
|
45
|
+
[x: string]: (id: any) => any[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 刷新参数
|
|
49
|
+
*/
|
|
50
|
+
refreshParams(pidMap: any): void;
|
|
51
|
+
/**
|
|
52
|
+
* 选举出一个进程
|
|
53
|
+
*/
|
|
54
|
+
pickOne(...params: any[]): any;
|
|
55
|
+
/**
|
|
56
|
+
* 选举出多个进程
|
|
57
|
+
*/
|
|
58
|
+
pickMulti(count?: number, ...params: any[]): any[];
|
|
59
|
+
/**
|
|
60
|
+
* 计算权重
|
|
61
|
+
*/
|
|
62
|
+
calculateWeightIndex(): void;
|
|
63
|
+
/**
|
|
64
|
+
* 计算索引
|
|
65
|
+
*/
|
|
66
|
+
calculateIndex(): void;
|
|
67
|
+
/**
|
|
68
|
+
* 清除data
|
|
69
|
+
*/
|
|
70
|
+
clean(id: any): void;
|
|
71
|
+
/**
|
|
72
|
+
* 添加一个进程信息
|
|
73
|
+
*/
|
|
74
|
+
add(task: any): void;
|
|
75
|
+
/**
|
|
76
|
+
* 删除一个进程信息
|
|
77
|
+
*/
|
|
78
|
+
del(target: any): void;
|
|
79
|
+
/**
|
|
80
|
+
* 擦除
|
|
81
|
+
*/
|
|
82
|
+
wipe(): void;
|
|
83
|
+
/**
|
|
84
|
+
* 更新计算参数
|
|
85
|
+
*/
|
|
86
|
+
updateParams(object: any): void;
|
|
87
|
+
/**
|
|
88
|
+
* 设置targets
|
|
89
|
+
*/
|
|
90
|
+
setTargets(targets: any): void;
|
|
91
|
+
/**
|
|
92
|
+
* 设置算法
|
|
93
|
+
*/
|
|
94
|
+
setAlgorithm: (algorithm: any) => void;
|
|
95
|
+
}
|
|
96
|
+
import Scheduler = require("./scheduler");
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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;
|