ee-core 4.0.0-beta.1 → 4.0.1
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/boot.d.ts +5 -0
- package/app/boot.js +0 -7
- package/app/dir.d.ts +1 -0
- package/app/events.d.ts +14 -0
- package/app/index.d.ts +2 -0
- package/config/config_loader.d.ts +13 -0
- package/config/default_config.d.ts +95 -0
- package/config/default_config.js +2 -1
- package/config/index.d.ts +28 -0
- package/const/channel.d.ts +16 -0
- package/const/channel.js +1 -1
- package/controller/controller_loader.d.ts +9 -0
- package/controller/index.d.ts +2 -0
- package/core/index.d.ts +2 -0
- package/core/loader/file_loader.d.ts +66 -0
- package/core/utils/index.d.ts +12 -0
- package/core/utils/timing.d.ts +22 -0
- package/cross/cross.d.ts +19 -0
- package/cross/cross.js +5 -5
- package/cross/crossProcess.d.ts +29 -0
- package/cross/{spawnProcess.js → crossProcess.js} +12 -7
- package/cross/index.d.ts +2 -0
- package/cross/index.js +2 -2
- package/electron/app/index.d.ts +5 -0
- package/electron/index.d.ts +3 -0
- package/electron/window/index.d.ts +6 -0
- package/exception/index.d.ts +9 -0
- package/exception/index.js +8 -22
- package/html/index.d.ts +1 -0
- package/index.d.ts +2 -0
- package/jobs/child/app.d.ts +1 -0
- package/jobs/child/index.d.ts +13 -0
- package/jobs/child/index.js +2 -2
- package/jobs/child/jobProcess.d.ts +16 -0
- package/jobs/child/{forkProcess.js → jobProcess.js} +3 -18
- package/jobs/child-pool/index.d.ts +26 -0
- package/jobs/child-pool/index.js +13 -38
- package/jobs/index.d.ts +3 -0
- 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 +4 -22
- package/log/index.d.ts +5 -0
- package/log/logger.d.ts +2 -0
- package/message/childMessage.d.ts +10 -0
- package/message/childMessage.js +2 -12
- package/message/index.d.ts +3 -0
- package/package.json +8 -1
- package/ps/index.d.ts +37 -0
- package/ps/index.js +2 -12
- package/socket/httpServer.d.ts +8 -0
- package/socket/httpServer.js +10 -3
- package/socket/index.d.ts +10 -0
- package/socket/ipcServer.d.ts +9 -0
- package/socket/ipcServer.js +13 -6
- package/socket/socketServer.d.ts +10 -0
- package/socket/socketServer.js +7 -2
- package/storage/index.d.ts +5 -0
- package/storage/sqliteStorage.d.ts +16 -0
- package/storage/sqliteStorage.js +2 -2
- package/tsconfig.json +14 -0
- package/utils/extend.d.ts +2 -0
- package/utils/helper.d.ts +14 -0
- package/utils/helper.js +1 -11
- package/utils/index.d.ts +10 -0
- package/utils/index.js +7 -17
- package/utils/ip.d.ts +2 -0
- package/utils/is.d.ts +14 -0
- package/utils/json.d.ts +5 -0
- package/utils/pargv.d.ts +3 -0
- package/utils/port/index.d.ts +1 -0
- package/utils/wrap.d.ts +4 -0
- package/const/index.js +0 -5
|
@@ -9,10 +9,10 @@ const { getRandomString } = require('../../utils/helper');
|
|
|
9
9
|
const { getFullpath } = require('../../loader');
|
|
10
10
|
const { extend } = require('../../utils/extend');
|
|
11
11
|
|
|
12
|
-
class
|
|
12
|
+
class JobProcess {
|
|
13
13
|
constructor(host, opt = {}) {
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
let cwd = getBaseDir();
|
|
16
16
|
const appPath = path.join(__dirname, 'app.js');
|
|
17
17
|
if (isPackaged()) {
|
|
18
18
|
// todo fork的cwd目录为什么要在app.asar外 ?
|
|
@@ -41,9 +41,6 @@ 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) => {
|
|
@@ -78,9 +75,6 @@ class ForkProcess {
|
|
|
78
75
|
});
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
/**
|
|
82
|
-
* event emit
|
|
83
|
-
*/
|
|
84
78
|
_eventEmit(m) {
|
|
85
79
|
switch (m.eventReceiver) {
|
|
86
80
|
case Receiver.forkProcess:
|
|
@@ -96,9 +90,6 @@ class ForkProcess {
|
|
|
96
90
|
}
|
|
97
91
|
}
|
|
98
92
|
|
|
99
|
-
/**
|
|
100
|
-
* 分发任务
|
|
101
|
-
*/
|
|
102
93
|
dispatch(cmd, jobPath = '', ...params) {
|
|
103
94
|
// 消息对象
|
|
104
95
|
const mid = getRandomString();
|
|
@@ -114,9 +105,6 @@ class ForkProcess {
|
|
|
114
105
|
this.child.send(msg);
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
/**
|
|
118
|
-
* 调用job的方法
|
|
119
|
-
*/
|
|
120
108
|
callFunc(jobPath = '', funcName = '', ...params) {
|
|
121
109
|
jobPath = getFullpath(jobPath);
|
|
122
110
|
|
|
@@ -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(() => {
|
|
@@ -145,5 +130,5 @@ class ForkProcess {
|
|
|
145
130
|
}
|
|
146
131
|
|
|
147
132
|
module.exports = {
|
|
148
|
-
|
|
133
|
+
JobProcess
|
|
149
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,7 +1,7 @@
|
|
|
1
1
|
const EventEmitter = require('events');
|
|
2
2
|
const LoadBalancer = require('../load-balancer');
|
|
3
3
|
const { getFullpath } = require('../../loader');
|
|
4
|
-
const {
|
|
4
|
+
const { JobProcess } = require('../child/jobProcess');
|
|
5
5
|
const { Events } = require('../../const/channel');
|
|
6
6
|
const { validValue } = require('../../utils/helper');
|
|
7
7
|
const { getConfig } = require('../../config');
|
|
@@ -39,9 +39,6 @@ class ChildPoolJob extends EventEmitter {
|
|
|
39
39
|
this._initEvents();
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* 初始化监听
|
|
44
|
-
*/
|
|
45
42
|
_initEvents() {
|
|
46
43
|
this.on(Events.childProcessExit, (data) => {
|
|
47
44
|
this._removeChild(data.pid);
|
|
@@ -50,10 +47,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
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,9 +100,7 @@ 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
105
|
const jobPath = getFullpath(filepath);
|
|
119
106
|
const childProcess = this.getChild();
|
|
@@ -122,16 +109,12 @@ class ChildPoolJob extends EventEmitter {
|
|
|
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 => {
|
package/jobs/index.d.ts
ADDED
|
@@ -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;
|
package/loader/index.js
CHANGED
|
@@ -4,13 +4,7 @@ const path = require('path');
|
|
|
4
4
|
const CoreUtils = require('../core/utils');
|
|
5
5
|
const { getElectronDir } = require('../ps');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* 加载单个文件(如果是函数,将被执行)
|
|
9
|
-
*
|
|
10
|
-
* @param {String} filepath - fullpath
|
|
11
|
-
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
12
|
-
* @return {Object} exports
|
|
13
|
-
*/
|
|
7
|
+
// 加载单个文件(如果是函数,将被执行)
|
|
14
8
|
function loadFile(filepath, ...inject) {
|
|
15
9
|
const isAbsolute = path.isAbsolute(filepath);
|
|
16
10
|
if (!isAbsolute) {
|
|
@@ -35,13 +29,7 @@ function requireFile(filepath) {
|
|
|
35
29
|
return CoreUtils.loadFile(filepath);
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
* 加载并运行文件
|
|
40
|
-
*
|
|
41
|
-
* @param {String} filepath - fullpath
|
|
42
|
-
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
43
|
-
* @return {Any}
|
|
44
|
-
*/
|
|
32
|
+
// 加载并运行文件
|
|
45
33
|
function execFile(filepath, ...inject) {
|
|
46
34
|
let ret = CoreUtils.loadFile(filepath);
|
|
47
35
|
if (is.class(ret) || CoreUtils.isBytecodeClass(ret)) {
|
|
@@ -53,10 +41,7 @@ function execFile(filepath, ...inject) {
|
|
|
53
41
|
return ret;
|
|
54
42
|
}
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
* 模块的绝对路径
|
|
58
|
-
* @param {String} filepath - fullpath
|
|
59
|
-
*/
|
|
44
|
+
// 模块的绝对路径
|
|
60
45
|
function resolveModule(filepath) {
|
|
61
46
|
let fullpath;
|
|
62
47
|
try {
|
|
@@ -80,10 +65,7 @@ function resolveModule(filepath) {
|
|
|
80
65
|
return fullpath;
|
|
81
66
|
}
|
|
82
67
|
|
|
83
|
-
|
|
84
|
-
* 获取electron目录下文件的绝对路径
|
|
85
|
-
* @param {String} filepath - fullpath
|
|
86
|
-
*/
|
|
68
|
+
// 获取electron目录下文件的绝对路径
|
|
87
69
|
function getFullpath(filepath) {
|
|
88
70
|
let fullpath;
|
|
89
71
|
const isAbsolute = path.isAbsolute(filepath);
|
package/log/index.d.ts
ADDED
package/log/logger.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class ChildMessage {
|
|
2
|
+
// 向主进程发消息 for ChildJob 实例
|
|
3
|
+
sendToMain(eventName: string, params?: {}): boolean;
|
|
4
|
+
// 向主进程发消息 for task 实例
|
|
5
|
+
send(eventName: string, params: {}, receiver?: string): boolean;
|
|
6
|
+
// 进程退出
|
|
7
|
+
exit(code?: number): never;
|
|
8
|
+
// 发送错误到控制台
|
|
9
|
+
sendErrorToTerminal(err: any): void;
|
|
10
|
+
}
|
package/message/childMessage.js
CHANGED
|
@@ -4,17 +4,13 @@ const { Receiver, Processes } = require('../const/channel');
|
|
|
4
4
|
|
|
5
5
|
class ChildMessage {
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* 向主进程发消息 for ChildJob 实例
|
|
9
|
-
*/
|
|
7
|
+
// Send a message to the main process for ChildJob instance
|
|
10
8
|
sendToMain(eventName, params = {}) {
|
|
11
9
|
const receiver = Receiver.childJob;
|
|
12
10
|
return this.send(eventName, params, receiver);
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
* 向主进程发消息 for task 实例
|
|
17
|
-
*/
|
|
13
|
+
// Send a message to the main process for a task instance
|
|
18
14
|
send(eventName, params = {}, receiver) {
|
|
19
15
|
const eventReceiver = receiver || Receiver.forkProcess;
|
|
20
16
|
const message = {
|
|
@@ -27,16 +23,10 @@ class ChildMessage {
|
|
|
27
23
|
return process.send(message);
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
/**
|
|
31
|
-
* 进程退出
|
|
32
|
-
*/
|
|
33
26
|
exit(code = 0) {
|
|
34
27
|
return process.exit(code);
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
/**
|
|
38
|
-
* 发送错误到控制台
|
|
39
|
-
*/
|
|
40
30
|
sendErrorToTerminal(err) {
|
|
41
31
|
let errTips = (err && typeof err == 'object') ? err.toString() : '';
|
|
42
32
|
errTips += ' Error !!! Please See file ee-core.log or ee-error-xxx.log for details !'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "ee core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,6 +33,13 @@
|
|
|
33
33
|
"serialize-javascript": "^6.0.1",
|
|
34
34
|
"socket.io": "^4.6.1",
|
|
35
35
|
"socket.io-client": "^4.6.1",
|
|
36
|
+
"tree-kill": "^1.2.2",
|
|
36
37
|
"urllib": "^2.38.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/better-sqlite3": "^7.6.12",
|
|
41
|
+
"@types/electron": "^1.4.38",
|
|
42
|
+
"@types/node": "^20.16.0",
|
|
43
|
+
"typescript": "^5.7.2"
|
|
37
44
|
}
|
|
38
45
|
}
|
package/ps/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare function allEnv(): NodeJS.ProcessEnv;
|
|
2
|
+
export declare function env(): string;
|
|
3
|
+
export declare function isProd(): boolean;
|
|
4
|
+
export declare function isDev(): boolean;
|
|
5
|
+
export declare function isRenderer(): boolean;
|
|
6
|
+
export declare function isMain(): boolean;
|
|
7
|
+
export declare function isForkedChild(): boolean;
|
|
8
|
+
export declare function processType(): string;
|
|
9
|
+
export declare function appName(): string;
|
|
10
|
+
export declare function appVersion(): string;
|
|
11
|
+
export declare function getDataDir(): string;
|
|
12
|
+
export declare function getLogDir(): string;
|
|
13
|
+
export declare function getBundleDir(basePath: string): string;
|
|
14
|
+
export declare function getRootDir(): string;
|
|
15
|
+
export declare function getBaseDir(): string;
|
|
16
|
+
export declare function getElectronDir(): string;
|
|
17
|
+
export declare function getPublicDir(): string;
|
|
18
|
+
export declare function getExtraResourcesDir(): string;
|
|
19
|
+
export declare function getAppUserDataDir(): string;
|
|
20
|
+
export declare function getExecDir(): string;
|
|
21
|
+
export declare function getUserHomeDir(): string;
|
|
22
|
+
export declare function getUserHomeAppDir(): string;
|
|
23
|
+
export declare function getUserHomeHiddenAppDir(): string;
|
|
24
|
+
export declare function getSocketPort(): number;
|
|
25
|
+
export declare function getHttpPort(): number;
|
|
26
|
+
export declare function isPackaged(): boolean;
|
|
27
|
+
export declare function isHotReload(): boolean;
|
|
28
|
+
export declare function exit(code?: number): never;
|
|
29
|
+
export declare function makeMessage(msg?: {}): {
|
|
30
|
+
channel: string;
|
|
31
|
+
event: string;
|
|
32
|
+
data: {};
|
|
33
|
+
};
|
|
34
|
+
export declare function exitChildJob(code?: number): void;
|
|
35
|
+
export declare function isChildJob(): boolean;
|
|
36
|
+
export declare function isChildPoolJob(): boolean;
|
|
37
|
+
export declare function getArgumentByName(name: string): string;
|
package/ps/index.js
CHANGED
|
@@ -18,9 +18,7 @@ function isProd() {
|
|
|
18
18
|
return (process.env.EE_ENV === 'prod');
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
* 是否为开发环境
|
|
23
|
-
*/
|
|
21
|
+
// 是否为开发环境
|
|
24
22
|
function isDev() {
|
|
25
23
|
if (process.env.EE_ENV === 'dev' || process.env.EE_ENV === 'local') {
|
|
26
24
|
return true;
|
|
@@ -174,18 +172,11 @@ function getHttpPort() {
|
|
|
174
172
|
return parseInt(process.env.EE_HTTP_PORT) || 0;
|
|
175
173
|
}
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
* 是否打包
|
|
179
|
-
*/
|
|
175
|
+
// 是否打包
|
|
180
176
|
function isPackaged() {
|
|
181
177
|
return process.env.EE_IS_PACKAGED === 'true';
|
|
182
178
|
}
|
|
183
179
|
|
|
184
|
-
// 是否热重启
|
|
185
|
-
function isHotReload() {
|
|
186
|
-
return process.env.HOT_RELOAD === 'true';
|
|
187
|
-
}
|
|
188
|
-
|
|
189
180
|
// 进程退出
|
|
190
181
|
function exit(code = 0) {
|
|
191
182
|
return process.exit(code);
|
|
@@ -276,7 +267,6 @@ module.exports = {
|
|
|
276
267
|
getSocketPort,
|
|
277
268
|
getHttpPort,
|
|
278
269
|
isPackaged,
|
|
279
|
-
isHotReload,
|
|
280
270
|
exit,
|
|
281
271
|
makeMessage,
|
|
282
272
|
exitChildJob,
|
package/socket/httpServer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const debug = require('debug')('ee-core:socket:httpServer');
|
|
3
4
|
const assert = require('assert');
|
|
4
5
|
const is = require('is-type-of');
|
|
5
6
|
const Koa = require('koa');
|
|
@@ -15,12 +16,16 @@ const { getController } = require('../controller');
|
|
|
15
16
|
const { getConfig } = require('../config');
|
|
16
17
|
const { getPort } = require('../utils/port');
|
|
17
18
|
|
|
19
|
+
let channelSeparator = '/';
|
|
20
|
+
|
|
18
21
|
/**
|
|
19
22
|
* http server
|
|
20
23
|
*/
|
|
21
24
|
class HttpServer {
|
|
22
25
|
constructor () {
|
|
23
|
-
|
|
26
|
+
const { httpServer, mainServer } = getConfig();
|
|
27
|
+
this.config = httpServer;
|
|
28
|
+
channelSeparator = mainServer.channelSeparator;
|
|
24
29
|
this.httpApp = undefined;
|
|
25
30
|
this.init();
|
|
26
31
|
}
|
|
@@ -117,11 +122,13 @@ class HttpServer {
|
|
|
117
122
|
if (uriPath.slice(0, 10) != 'controller') {
|
|
118
123
|
uriPath = 'controller/' + uriPath;
|
|
119
124
|
}
|
|
120
|
-
const cmd = uriPath.split('/').join(
|
|
125
|
+
const cmd = uriPath.split('/').join(channelSeparator);
|
|
126
|
+
debug('[request] uri %s', cmd);
|
|
121
127
|
const args = (method == 'POST') ? body: params;
|
|
122
128
|
let fn = null;
|
|
123
129
|
if (is.string(cmd)) {
|
|
124
|
-
const actions = cmd.split(
|
|
130
|
+
const actions = cmd.split(channelSeparator);
|
|
131
|
+
debug('[findFn] channel %o', actions);
|
|
125
132
|
let obj = { controller };
|
|
126
133
|
actions.forEach(key => {
|
|
127
134
|
obj = obj[key];
|