ee-core 2.5.0 → 2.6.0-beta.2
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/electron/app/index.js +0 -1
- package/html/boot.html +3 -2
- package/jobs/child/forkProcess.js +5 -1
- package/jobs/child/index.js +8 -0
- package/jobs/child-pool/index.js +8 -0
- package/package.json +1 -1
- package/socket/ipcServer.js +20 -9
- package/storage/index.js +2 -0
- package/storage/jsondb/adapters/Base.js +9 -0
- package/storage/jsondb/adapters/FileSync.js +29 -9
- package/storage/jsondbStorage.js +14 -2
package/electron/app/index.js
CHANGED
package/html/boot.html
CHANGED
|
@@ -44,8 +44,12 @@ class ForkProcess {
|
|
|
44
44
|
* 初始化事件监听
|
|
45
45
|
*/
|
|
46
46
|
_init() {
|
|
47
|
+
const { messageLog } = this.host.config;
|
|
47
48
|
this.child.on('message', (m) => {
|
|
48
|
-
|
|
49
|
+
if (messageLog == true) {
|
|
50
|
+
Log.coreLogger.info(`[ee-core] [jobs/child] received a message from child-process, message: ${serialize(m)}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
if (m.channel == Channel.process.showException) {
|
|
50
54
|
Log.coreLogger.error(`${m.data}`);
|
|
51
55
|
}
|
package/jobs/child/index.js
CHANGED
|
@@ -2,12 +2,20 @@ const EventEmitter = require('events');
|
|
|
2
2
|
const ForkProcess = require('./forkProcess');
|
|
3
3
|
const Loader = require('../../loader');
|
|
4
4
|
const Channel = require('../../const/channel');
|
|
5
|
+
const Conf = require('../../config');
|
|
5
6
|
|
|
6
7
|
class ChildJob extends EventEmitter {
|
|
7
8
|
|
|
8
9
|
constructor() {
|
|
9
10
|
super();
|
|
10
11
|
this.jobs = {};
|
|
12
|
+
this.config = {};
|
|
13
|
+
|
|
14
|
+
const cfg = Conf.getValue('jobs');
|
|
15
|
+
if (cfg) {
|
|
16
|
+
this.config = cfg;
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
this._initEvents();
|
|
12
20
|
}
|
|
13
21
|
|
package/jobs/child-pool/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const Loader = require('../../loader');
|
|
|
4
4
|
const ForkProcess = require('../child/forkProcess');
|
|
5
5
|
const Channel = require('../../const/channel');
|
|
6
6
|
const Helper = require('../../utils/helper');
|
|
7
|
+
const Conf = require('../../config');
|
|
7
8
|
|
|
8
9
|
class ChildPoolJob extends EventEmitter {
|
|
9
10
|
|
|
@@ -13,6 +14,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
13
14
|
weights: [],
|
|
14
15
|
}, opt);
|
|
15
16
|
|
|
17
|
+
this.config = {};
|
|
16
18
|
this.boundMap = new Map();
|
|
17
19
|
this.children = {};
|
|
18
20
|
this.min = 3;
|
|
@@ -28,6 +30,12 @@ class ChildPoolJob extends EventEmitter {
|
|
|
28
30
|
targets: [],
|
|
29
31
|
}
|
|
30
32
|
this.LB = new LoadBalancer(lbOpt);
|
|
33
|
+
|
|
34
|
+
const cfg = Conf.getValue('jobs');
|
|
35
|
+
if (cfg) {
|
|
36
|
+
this.config = cfg;
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
this._initEvents();
|
|
32
40
|
}
|
|
33
41
|
|
package/package.json
CHANGED
package/socket/ipcServer.js
CHANGED
|
@@ -80,19 +80,30 @@ class IpcServer {
|
|
|
80
80
|
|
|
81
81
|
// send/on 模型
|
|
82
82
|
ipcMain.on(channel, async (event, params) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
try {
|
|
84
|
+
const fn = findFn(self.app, channel);
|
|
85
|
+
const result = await fn.call(self.app, params, event);
|
|
86
|
+
|
|
87
|
+
event.returnValue = result;
|
|
88
|
+
event.reply(`${channel}`, result);
|
|
89
|
+
} catch(e) {
|
|
90
|
+
Log.coreLogger.error('[ee-core] [socket/IpcServer] send/on throw error:', e);
|
|
91
|
+
// event.returnValue = e;
|
|
92
|
+
// event.reply(`${channel}`, e);
|
|
93
|
+
}
|
|
88
94
|
});
|
|
89
95
|
|
|
90
96
|
// invoke/handle 模型
|
|
91
97
|
ipcMain.handle(channel, async (event, params) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
try {
|
|
99
|
+
const fn = findFn(self.app, channel);
|
|
100
|
+
const result = await fn.call(self.app, params, event);
|
|
101
|
+
|
|
102
|
+
return result;
|
|
103
|
+
} catch(e) {
|
|
104
|
+
Log.coreLogger.error('[ee-core] [socket/IpcServer] invoke/handle throw error:', e);
|
|
105
|
+
return e
|
|
106
|
+
}
|
|
96
107
|
});
|
|
97
108
|
}
|
|
98
109
|
}
|
package/storage/index.js
CHANGED
|
@@ -1,30 +1,50 @@
|
|
|
1
1
|
const Base = require('./Base')
|
|
2
2
|
const fs = require('fs')
|
|
3
|
+
const Log = require('../../../log')
|
|
3
4
|
|
|
4
5
|
class FileSync extends Base {
|
|
6
|
+
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
const { source, isSysDB } = options;
|
|
9
|
+
super(source);
|
|
10
|
+
this.isSysDB = isSysDB;
|
|
11
|
+
}
|
|
5
12
|
|
|
6
13
|
read() {
|
|
7
14
|
if (fs.existsSync(this.source)) {
|
|
8
15
|
// Read database
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
const data = fs.readFileSync(this.source, {encoding: 'utf8'}).trim();
|
|
17
|
+
|
|
18
|
+
const canDeserialized = this._canDeserialized(data);
|
|
19
|
+
if (!canDeserialized) {
|
|
20
|
+
const errMessage = `Malformed JSON in file: ${this.source}\n${data}`;
|
|
21
|
+
console.error(errMessage)
|
|
11
22
|
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (e instanceof SyntaxError) {
|
|
16
|
-
e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
|
|
23
|
+
// reset system.json
|
|
24
|
+
if (this.isSysDB) {
|
|
25
|
+
this._fsWrite(this.defaultValue);
|
|
17
26
|
}
|
|
18
|
-
throw e
|
|
19
27
|
}
|
|
28
|
+
const value = canDeserialized ? this.deserialize(data) : this.defaultValue;
|
|
29
|
+
return value;
|
|
20
30
|
} else {
|
|
21
31
|
// Initialize
|
|
22
|
-
|
|
32
|
+
this._fsWrite(this.defaultValue);
|
|
23
33
|
return this.defaultValue
|
|
24
34
|
}
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
write(data) {
|
|
38
|
+
return this._fsWrite(data);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_fsWrite(data) {
|
|
42
|
+
const isObject = Object.prototype.toString.call(data) === '[object Object]';
|
|
43
|
+
if (!isObject) {
|
|
44
|
+
Log.coreLogger.error('[ee-core] [storage/jsondb] Variable is not an object :', data);
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
return fs.writeFileSync(this.source, this.serialize(data), {flag:'w+'})
|
|
29
49
|
}
|
|
30
50
|
}
|
package/storage/jsondbStorage.js
CHANGED
|
@@ -28,7 +28,12 @@ class JsondbStorage {
|
|
|
28
28
|
*/
|
|
29
29
|
table() {
|
|
30
30
|
const dbFile = this.getFilePath();
|
|
31
|
-
const
|
|
31
|
+
const isSysDB = this.isSystemDB();
|
|
32
|
+
const opt = {
|
|
33
|
+
source: dbFile,
|
|
34
|
+
isSysDB: isSysDB
|
|
35
|
+
}
|
|
36
|
+
const adapter = new FileSync(opt);
|
|
32
37
|
const db = Jsondb(adapter);
|
|
33
38
|
|
|
34
39
|
assert(fs.existsSync(dbFile), `error: storage ${dbFile} not exists`);
|
|
@@ -36,7 +41,7 @@ class JsondbStorage {
|
|
|
36
41
|
return db;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
/**
|
|
44
|
+
/**
|
|
40
45
|
* 补全扩展名
|
|
41
46
|
*/
|
|
42
47
|
_addExtname(name) {
|
|
@@ -73,6 +78,13 @@ class JsondbStorage {
|
|
|
73
78
|
return fileName;
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
/**
|
|
82
|
+
* is system db
|
|
83
|
+
*/
|
|
84
|
+
isSystemDB() {
|
|
85
|
+
return (this.name == 'system.json') ? true : false;
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
/**
|
|
77
89
|
* 获取文件绝对路径
|
|
78
90
|
*/
|