ee-core 2.0.0-beta.1 → 2.0.0-beta.3
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/bin/tools.js +1 -1
- package/core/lib/loader/context_loader.js +2 -2
- package/core/lib/loader/ee_loader.js +20 -46
- package/core/lib/loader/file_loader.js +6 -6
- package/core/lib/loader/mixin/config.js +7 -12
- package/core/lib/loader/mixin/controller.js +8 -8
- package/core/lib/utils/index.js +6 -0
- package/lib/application.js +5 -3
- package/lib/eeApp.js +5 -5
- package/module/exception/index.js +16 -0
- package/module/httpclient/index.js +2 -2
- package/module/jobs/child/app.js +43 -0
- package/module/jobs/child/forkProcess.js +48 -65
- package/module/jobs/child/index.js +46 -18
- package/module/jobs/child/pool.js +67 -0
- package/module/jobs/index.js +5 -53
- package/module/jobs/unification.js +64 -0
- package/module/loader/index.js +72 -20
- package/module/message/childMessage.js +63 -0
- package/module/message/index.js +24 -9
- package/module/message/manager.js +0 -0
- package/module/message/messenger.js +0 -0
- package/module/socket/httpServer.js +4 -3
- package/module/socket/ipcServer.js +3 -6
- package/module/socket/socketClient.js +1 -4
- package/module/socket/socketServer.js +4 -6
- package/module/storage/index.js +6 -4
- package/module/storage/jsondb/adapters/FileSync.js +3 -3
- package/module/storage/jsondbStorage.js +0 -1
- package/module/utils/helper.js +2 -2
- package/module/utils/index.js +1 -35
- package/module/utils/ps.js +48 -2
- package/package.json +1 -1
- package/tools/encrypt.js +10 -10
- package/tools/replaceDist.js +6 -6
- package/utils/index.js +0 -23
package/bin/tools.js
CHANGED
|
@@ -7,7 +7,7 @@ const encrypt = require('../tools/encrypt');
|
|
|
7
7
|
const args = process.argv;
|
|
8
8
|
// console.log('[ee-core] args:', args);
|
|
9
9
|
const cmd = args[2];
|
|
10
|
-
console.log('[ee-core] cmd:', cmd);
|
|
10
|
+
console.log('[ee-core] [bin/tools] cmd:', cmd);
|
|
11
11
|
|
|
12
12
|
if (cmd == 'rd') {
|
|
13
13
|
replaceDist.run();
|
|
@@ -5,7 +5,7 @@ const is = require('is-type-of');
|
|
|
5
5
|
const FileLoader = require('./file_loader');
|
|
6
6
|
const CLASSLOADER = Symbol('classLoader');
|
|
7
7
|
const EXPORTS = FileLoader.EXPORTS;
|
|
8
|
-
const
|
|
8
|
+
const Utils = require('../utils');
|
|
9
9
|
|
|
10
10
|
class ClassLoader {
|
|
11
11
|
|
|
@@ -89,7 +89,7 @@ function getInstance(values, ctx) {
|
|
|
89
89
|
const Class = values[EXPORTS] ? values : null;
|
|
90
90
|
let instance;
|
|
91
91
|
if (Class) {
|
|
92
|
-
if (is.class(Class) ||
|
|
92
|
+
if (is.class(Class) || Utils.isBytecodeClass(Class)) {
|
|
93
93
|
instance = new Class(ctx);
|
|
94
94
|
} else {
|
|
95
95
|
// it's just an object
|
|
@@ -7,7 +7,7 @@ const is = require('is-type-of');
|
|
|
7
7
|
const debug = require('debug')('ee-core:EeLoader');
|
|
8
8
|
const FileLoader = require('./file_loader');
|
|
9
9
|
const ContextLoader = require('./context_loader');
|
|
10
|
-
const
|
|
10
|
+
const Utils = require('../utils');
|
|
11
11
|
const Timing = require('../utils/timing');
|
|
12
12
|
const Ps = require('../../../module/utils/ps');
|
|
13
13
|
|
|
@@ -83,25 +83,8 @@ class EeLoader {
|
|
|
83
83
|
getServerEnv() {
|
|
84
84
|
let serverEnv = this.options.env;
|
|
85
85
|
|
|
86
|
-
const envPath = path.join(this.options.baseDir, 'config/env');
|
|
87
|
-
if (!serverEnv && fs.existsSync(envPath)) {
|
|
88
|
-
serverEnv = fs.readFileSync(envPath, 'utf8').trim();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (!serverEnv) {
|
|
92
|
-
serverEnv = process.env.EE_SERVER_ENV;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
86
|
if (!serverEnv) {
|
|
96
|
-
|
|
97
|
-
serverEnv = 'unittest';
|
|
98
|
-
} else if (process.env.NODE_ENV === 'production') {
|
|
99
|
-
serverEnv = 'prod';
|
|
100
|
-
} else {
|
|
101
|
-
serverEnv = 'local';
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
serverEnv = serverEnv.trim();
|
|
87
|
+
throw new Error('[core] [lib] [loader] getServerEnv serverEnv can not be empty!');
|
|
105
88
|
}
|
|
106
89
|
|
|
107
90
|
return serverEnv;
|
|
@@ -272,7 +255,7 @@ class EeLoader {
|
|
|
272
255
|
if (inject.length === 0) inject = [ this.app ];
|
|
273
256
|
|
|
274
257
|
let ret = this.requireFile(filepath);
|
|
275
|
-
if (is.function(ret) && !is.class(ret) && !
|
|
258
|
+
if (is.function(ret) && !is.class(ret) && !Utils.isBytecodeClass(ret)) {
|
|
276
259
|
ret = ret(...inject);
|
|
277
260
|
}
|
|
278
261
|
return ret;
|
|
@@ -284,9 +267,9 @@ class EeLoader {
|
|
|
284
267
|
* @private
|
|
285
268
|
*/
|
|
286
269
|
requireFile(filepath) {
|
|
287
|
-
const timingKey = `Require(${this[REQUIRE_COUNT]++}) ${
|
|
270
|
+
const timingKey = `Require(${this[REQUIRE_COUNT]++}) ${Utils.getResolvedFilename(filepath, this.options.baseDir)}`;
|
|
288
271
|
this.timing.start(timingKey);
|
|
289
|
-
const ret =
|
|
272
|
+
const ret = Utils.loadFile(filepath);
|
|
290
273
|
this.timing.end(timingKey);
|
|
291
274
|
return ret;
|
|
292
275
|
}
|
|
@@ -313,15 +296,6 @@ class EeLoader {
|
|
|
313
296
|
|
|
314
297
|
const dirs = this.dirs = [];
|
|
315
298
|
|
|
316
|
-
if (this.orderPlugins) {
|
|
317
|
-
for (const plugin of this.orderPlugins) {
|
|
318
|
-
dirs.push({
|
|
319
|
-
path: plugin.path,
|
|
320
|
-
type: 'plugin',
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
299
|
// framework or Ee path
|
|
326
300
|
for (const EePath of this.EePaths) {
|
|
327
301
|
dirs.push({
|
|
@@ -404,31 +378,31 @@ class EeLoader {
|
|
|
404
378
|
|
|
405
379
|
getTypeFiles(filename) {
|
|
406
380
|
const files = [ `${filename}.default` ];
|
|
407
|
-
if (this.serverScope) files.push(`${filename}.${this.serverScope}`);
|
|
408
|
-
if (this.serverEnv === 'default') return files;
|
|
409
|
-
|
|
410
381
|
files.push(`${filename}.${this.serverEnv}`);
|
|
411
|
-
|
|
382
|
+
|
|
412
383
|
return files;
|
|
413
384
|
}
|
|
414
385
|
|
|
415
386
|
resolveModule(filepath) {
|
|
416
|
-
let
|
|
387
|
+
let fullpath;
|
|
417
388
|
try {
|
|
418
|
-
|
|
389
|
+
fullpath = require.resolve(filepath);
|
|
419
390
|
} catch (e) {
|
|
420
|
-
let jscFile = filepath + '.jsc';
|
|
421
|
-
if (fs.existsSync(jscFile)) {
|
|
422
|
-
return jscFile;
|
|
423
|
-
}
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
391
|
|
|
427
|
-
|
|
428
|
-
|
|
392
|
+
// 特殊后缀处理
|
|
393
|
+
if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
|
|
394
|
+
fullpath = filepath + '.jsc';
|
|
395
|
+
} else if (filepath && filepath.endsWith('.js')) {
|
|
396
|
+
fullpath = filepath + 'c';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
400
|
+
this.options.logger.warn(`[ee-core] [core/lib/loader/ee_loader] resolveModule unknow filepath: ${filepath}`)
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
429
403
|
}
|
|
430
404
|
|
|
431
|
-
return
|
|
405
|
+
return fullpath;
|
|
432
406
|
}
|
|
433
407
|
|
|
434
408
|
getPkg() {
|
|
@@ -7,7 +7,7 @@ const path = require('path');
|
|
|
7
7
|
const globby = require('globby');
|
|
8
8
|
const is = require('is-type-of');
|
|
9
9
|
const deprecate = require('depd')('ee');
|
|
10
|
-
const
|
|
10
|
+
const Utils = require('../utils');
|
|
11
11
|
const FULLPATH = Symbol('EE_LOADER_ITEM_FULLPATH');
|
|
12
12
|
const EXPORTS = Symbol('EE_LOADER_ITEM_EXPORTS');
|
|
13
13
|
|
|
@@ -125,7 +125,7 @@ class FileLoader {
|
|
|
125
125
|
parse() {
|
|
126
126
|
let files = this.options.match;
|
|
127
127
|
if (!files) {
|
|
128
|
-
files = (process.env.EE_TYPESCRIPT === 'true' &&
|
|
128
|
+
files = (process.env.EE_TYPESCRIPT === 'true' && Utils.extensions['.ts'])
|
|
129
129
|
? [ '**/*.(js|ts)', '!**/*.d.ts' ]
|
|
130
130
|
: [ '**/*.js', '**/*.jsc'];
|
|
131
131
|
} else {
|
|
@@ -164,7 +164,7 @@ class FileLoader {
|
|
|
164
164
|
if (exports == null || (filter && filter(exports) === false)) continue;
|
|
165
165
|
|
|
166
166
|
// set properties of class
|
|
167
|
-
if (is.class(exports) ||
|
|
167
|
+
if (is.class(exports) || Utils.isBytecodeClass(exports)) {
|
|
168
168
|
exports.prototype.pathName = pathName;
|
|
169
169
|
exports.prototype.fullPath = fullpath;
|
|
170
170
|
}
|
|
@@ -217,7 +217,7 @@ class FileLoader {
|
|
|
217
217
|
if (exports == null) continue;
|
|
218
218
|
|
|
219
219
|
const properties = [addonName];
|
|
220
|
-
if (is.class(exports) ||
|
|
220
|
+
if (is.class(exports) || Utils.isBytecodeClass(exports)) {
|
|
221
221
|
exports.prototype.pathName = addonName;
|
|
222
222
|
exports.prototype.fullPath = fullpath;
|
|
223
223
|
}
|
|
@@ -261,7 +261,7 @@ function getProperties(filepath, { caseStyle }) {
|
|
|
261
261
|
// Get exports from filepath
|
|
262
262
|
// If exports is null/undefined, it will be ignored
|
|
263
263
|
function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
264
|
-
let exports =
|
|
264
|
+
let exports = Utils.loadFile(fullpath);
|
|
265
265
|
|
|
266
266
|
// process exports as you like
|
|
267
267
|
if (initializer) {
|
|
@@ -275,7 +275,7 @@ function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
|
275
275
|
// module.exports = function*() {}
|
|
276
276
|
//new exports;
|
|
277
277
|
|
|
278
|
-
if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports) ||
|
|
278
|
+
if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports) || Utils.isBytecodeClass(exports)) {
|
|
279
279
|
return exports;
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -24,14 +24,7 @@ module.exports = {
|
|
|
24
24
|
|
|
25
25
|
// Load Application config first
|
|
26
26
|
const appConfig = this._preloadAppConfig();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// plugin config.default
|
|
30
|
-
// framework config.default
|
|
31
|
-
// app config.default
|
|
32
|
-
// plugin config.{env}
|
|
33
|
-
// framework config.{env}
|
|
34
|
-
// app config.{env}
|
|
27
|
+
|
|
35
28
|
for (const filename of this.getTypeFiles('config')) {
|
|
36
29
|
for (const unit of this.getLoadUnits()) {
|
|
37
30
|
const isApp = unit.type === 'app';
|
|
@@ -64,6 +57,8 @@ module.exports = {
|
|
|
64
57
|
'config.default',
|
|
65
58
|
`config.${this.serverEnv}`,
|
|
66
59
|
];
|
|
60
|
+
|
|
61
|
+
|
|
67
62
|
const target = {};
|
|
68
63
|
for (const filename of names) {
|
|
69
64
|
const config = this._loadConfig(this.options.baseDir, filename, undefined, 'app');
|
|
@@ -78,9 +73,9 @@ module.exports = {
|
|
|
78
73
|
let filepath = this.resolveModule(path.join(dirpath, 'config', filename));
|
|
79
74
|
|
|
80
75
|
// let config.js compatible
|
|
81
|
-
if (filename === 'config.default' && !filepath) {
|
|
82
|
-
|
|
83
|
-
}
|
|
76
|
+
// if (filename === 'config.default' && !filepath) {
|
|
77
|
+
// filepath = this.resolveModule(path.join(dirpath, 'config/config'));
|
|
78
|
+
// }
|
|
84
79
|
|
|
85
80
|
const config = this.loadFile(filepath, this.appInfo, extraInject);
|
|
86
81
|
|
|
@@ -107,7 +102,7 @@ module.exports = {
|
|
|
107
102
|
this._setConfigMeta(envConfig, '<process.env.EE_APP_CONFIG>');
|
|
108
103
|
return envConfig;
|
|
109
104
|
} catch (err) {
|
|
110
|
-
this.options.logger.warn('[ee-
|
|
105
|
+
this.options.logger.warn('[ee-core] [core/.../config] process.env.EE_APP_CONFIG is not invalid JSON: %s', envConfigStr);
|
|
111
106
|
}
|
|
112
107
|
},
|
|
113
108
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const is = require('is-type-of');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const UtilsFn = require('../../utils/function');
|
|
6
|
+
const Utils = require('../../utils');
|
|
7
7
|
const FULLPATH = require('../file_loader').FULLPATH;
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
@@ -26,10 +26,10 @@ module.exports = {
|
|
|
26
26
|
// }
|
|
27
27
|
// ```
|
|
28
28
|
|
|
29
|
-
if (is.function(obj) && !is.generatorFunction(obj) && !is.class(obj) && !is.asyncFunction(obj) && !
|
|
29
|
+
if (is.function(obj) && !is.generatorFunction(obj) && !is.class(obj) && !is.asyncFunction(obj) && !Utils.isBytecodeClass(obj)) {
|
|
30
30
|
obj = obj(this.app);
|
|
31
31
|
}
|
|
32
|
-
if (is.class(obj) ||
|
|
32
|
+
if (is.class(obj) || Utils.isBytecodeClass(obj)) {
|
|
33
33
|
obj.prototype.pathName = opt.pathName;
|
|
34
34
|
obj.prototype.fullPath = opt.path;
|
|
35
35
|
return wrapClass(obj);
|
|
@@ -47,7 +47,7 @@ module.exports = {
|
|
|
47
47
|
const controllerBase = opt.directory;
|
|
48
48
|
|
|
49
49
|
this.loadToApp(controllerBase, 'controller', opt);
|
|
50
|
-
this.options.logger.info('[ee-core
|
|
50
|
+
this.options.logger.info('[ee-core] [core/.../controller] loaded: %s', controllerBase);
|
|
51
51
|
this.timing.end('Load Controller');
|
|
52
52
|
},
|
|
53
53
|
|
|
@@ -86,7 +86,7 @@ function wrapClass(Controller) {
|
|
|
86
86
|
// args = [ this ];
|
|
87
87
|
// }
|
|
88
88
|
//args = [ this ];
|
|
89
|
-
return
|
|
89
|
+
return Utils.callFn(controller[key], args, controller);
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -97,7 +97,7 @@ function wrapObject(obj, path, prefix) {
|
|
|
97
97
|
const ret = {};
|
|
98
98
|
for (const key of keys) {
|
|
99
99
|
if (is.function(obj[key])) {
|
|
100
|
-
const names =
|
|
100
|
+
const names = UtilsFn.getParamNames(obj[key]);
|
|
101
101
|
if (names[0] === 'next') {
|
|
102
102
|
throw new Error(`controller \`${prefix || ''}${key}\` should not use next as argument from file ${path}`);
|
|
103
103
|
}
|
|
@@ -114,7 +114,7 @@ function wrapObject(obj, path, prefix) {
|
|
|
114
114
|
// if (!this.app.config.controller || !this.app.config.controller.supportParams) {
|
|
115
115
|
// args = [ this ];
|
|
116
116
|
// }
|
|
117
|
-
return await
|
|
117
|
+
return await Utils.callFn(func, args, this);
|
|
118
118
|
};
|
|
119
119
|
for (const key in func) {
|
|
120
120
|
objectControllerMiddleware[key] = func[key];
|
package/core/lib/utils/index.js
CHANGED
|
@@ -14,6 +14,12 @@ const Module = module.constructor.length > 1
|
|
|
14
14
|
/* istanbul ignore next */
|
|
15
15
|
: BuiltinModule;
|
|
16
16
|
|
|
17
|
+
// Module._extensions:
|
|
18
|
+
// '.js': [Function (anonymous)],
|
|
19
|
+
// '.json': [Function (anonymous)],
|
|
20
|
+
// '.node': [Function: func],
|
|
21
|
+
// '.jsc': [Function (anonymous)]
|
|
22
|
+
|
|
17
23
|
module.exports = {
|
|
18
24
|
extensions: Module._extensions,
|
|
19
25
|
|
package/lib/application.js
CHANGED
|
@@ -20,7 +20,8 @@ class Appliaction extends EeApp {
|
|
|
20
20
|
appUserData: app.getPath('userData'),
|
|
21
21
|
appVersion: app.getVersion(),
|
|
22
22
|
isPackaged: app.isPackaged,
|
|
23
|
-
execDir: app.getAppPath()
|
|
23
|
+
execDir: app.getAppPath(),
|
|
24
|
+
isEncrypted: false
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
// argv
|
|
@@ -42,9 +43,9 @@ class Appliaction extends EeApp {
|
|
|
42
43
|
|
|
43
44
|
// Use encryption, base directory is public/electron
|
|
44
45
|
const encryptDir = path.join(app.getAppPath(), 'public', 'electron');
|
|
45
|
-
|
|
46
|
-
if (options.env == 'prod' && isEncrypted) {
|
|
46
|
+
if (options.env == 'prod' && fs.existsSync(encryptDir)) {
|
|
47
47
|
options.baseDir = encryptDir;
|
|
48
|
+
options.isEncrypted = true;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
// normalize env
|
|
@@ -59,6 +60,7 @@ class Appliaction extends EeApp {
|
|
|
59
60
|
env.HOT_RELOAD = hotReload;
|
|
60
61
|
env.EE_EXEC_DIR = options.execDir;
|
|
61
62
|
env.EE_IS_PACKAGED = options.isPackaged;
|
|
63
|
+
env.EE_IS_ENCRYPTED = options.isEncrypted;
|
|
62
64
|
env.EE_DATABASE_DIR = null;
|
|
63
65
|
env.EE_MAIN_PORT = null;
|
|
64
66
|
env.EE_SOCKET_PORT = null;
|
package/lib/eeApp.js
CHANGED
|
@@ -80,7 +80,7 @@ class EeApp extends BaseApp {
|
|
|
80
80
|
|
|
81
81
|
app.on('window-all-closed', () => {
|
|
82
82
|
if (process.platform !== 'darwin') {
|
|
83
|
-
Log.coreLogger.info('[
|
|
83
|
+
Log.coreLogger.info('[ee-core] [lib/eeApp] window-all-closed quit');
|
|
84
84
|
self.appQuit();
|
|
85
85
|
}
|
|
86
86
|
})
|
|
@@ -105,7 +105,7 @@ class EeApp extends BaseApp {
|
|
|
105
105
|
const protocolName = 'eefile';
|
|
106
106
|
protocol.registerFileProtocol(protocolName, (request, callback) => {
|
|
107
107
|
const url = request.url.substring(protocolName.length + 3);
|
|
108
|
-
console.log('[ee-core
|
|
108
|
+
console.log('[ee-core] [lib/eeApp] registerFileProtocol ----url: ', url);
|
|
109
109
|
callback({ path: path.normalize(decodeURIComponent(url)) })
|
|
110
110
|
});
|
|
111
111
|
|
|
@@ -220,7 +220,7 @@ class EeApp extends BaseApp {
|
|
|
220
220
|
};
|
|
221
221
|
https.createServer(sslOpt, koaApp.callback()).listen(mainServer.port, (err) => {
|
|
222
222
|
if (err) {
|
|
223
|
-
Log.coreLogger.info('[
|
|
223
|
+
Log.coreLogger.info('[ee-core] [lib/eeApp] createServer error: ', err);
|
|
224
224
|
return
|
|
225
225
|
}
|
|
226
226
|
self.loadMainUrl(mode, url);
|
|
@@ -237,8 +237,8 @@ class EeApp extends BaseApp {
|
|
|
237
237
|
*/
|
|
238
238
|
loadMainUrl (type, url) {
|
|
239
239
|
const mainServer = this.config.mainServer;
|
|
240
|
-
Log.coreLogger.info('[ee-core
|
|
241
|
-
Log.coreLogger.info('[ee-core
|
|
240
|
+
Log.coreLogger.info('[ee-core] [main] Env: %s, Type: %s', this.config.env, type);
|
|
241
|
+
Log.coreLogger.info('[ee-core] [main] App running at: %s', url);
|
|
242
242
|
this.electron.mainWindow.loadURL(url, mainServer.options);
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const Log = require('../log');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 捕获异常
|
|
5
|
+
*/
|
|
6
|
+
exports.start = function() {
|
|
7
|
+
process.on('uncaughtException', this.uncaughtExceptionHandler);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.uncaughtExceptionHandler = function(err) {
|
|
11
|
+
if (!(err instanceof Error)) {
|
|
12
|
+
err = new Error(String(err));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Log.coreLogger.error(err);
|
|
16
|
+
}
|
|
@@ -152,12 +152,12 @@ function normalizeConfig(httpConfig) {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
if (config.httpAgent.timeout < 30000) {
|
|
155
|
-
Log.coreLogger.warn('[ee
|
|
155
|
+
Log.coreLogger.warn('[ee-core] [module/httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
156
156
|
config.httpAgent.timeout);
|
|
157
157
|
config.httpAgent.timeout = 30000;
|
|
158
158
|
}
|
|
159
159
|
if (config.httpsAgent.timeout < 30000) {
|
|
160
|
-
Log.coreLogger.warn('[ee
|
|
160
|
+
Log.coreLogger.warn('[ee-core] [module/httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
161
161
|
config.httpsAgent.timeout);
|
|
162
162
|
config.httpsAgent.timeout = 30000;
|
|
163
163
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
const Exception = require('ee-core/module/exception');
|
|
3
|
+
Exception.start();
|
|
4
|
+
const Loader = require('ee-core/module/loader');
|
|
5
|
+
const Log = require('ee-core/module/log');
|
|
6
|
+
|
|
7
|
+
class ChildApp {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._initEvents();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 初始化事件监听
|
|
14
|
+
*/
|
|
15
|
+
_initEvents() {
|
|
16
|
+
Log.info('[ee-core] [child-process] init Events');
|
|
17
|
+
|
|
18
|
+
process.on('disconnect', () => {
|
|
19
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process disconnected:${process.pid} !`);
|
|
20
|
+
});
|
|
21
|
+
process.on('exit', () => {
|
|
22
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process exited:${process.pid} !`);
|
|
23
|
+
});
|
|
24
|
+
process.on('message', this._handleMessage.bind(this));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 监听消息
|
|
29
|
+
*/
|
|
30
|
+
_handleMessage(message) {
|
|
31
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] Received a message ${message} from the mainProcess`);
|
|
32
|
+
|
|
33
|
+
this.run(message);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
run(msg = {}) {
|
|
37
|
+
Log.coreLogger.info('[ee-core] [child-process] run');
|
|
38
|
+
|
|
39
|
+
Loader.loadJobFile(msg.jobPath, msg.params);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
new ChildApp();
|
|
@@ -1,99 +1,82 @@
|
|
|
1
|
+
const path = require('path');
|
|
1
2
|
const { fork } = require('child_process');
|
|
3
|
+
const Log = require('../../log');
|
|
4
|
+
const Ps = require('../../utils/ps');
|
|
2
5
|
|
|
3
6
|
class ForkProcess {
|
|
4
|
-
constructor(host,
|
|
7
|
+
constructor(host, opt = {}) {
|
|
8
|
+
|
|
9
|
+
let processCWD = Ps.getHomeDir();
|
|
10
|
+
// if (Ps.isDev()) {
|
|
11
|
+
// cwd = path.join(Ps.getHomeDir());
|
|
12
|
+
// }
|
|
13
|
+
|
|
14
|
+
let options = Object.assign({
|
|
15
|
+
params: {},
|
|
16
|
+
processOptions: {
|
|
17
|
+
cwd: processCWD,
|
|
18
|
+
env: Ps.allEnv(),
|
|
19
|
+
stdio: 'pipe'
|
|
20
|
+
}
|
|
21
|
+
}, opt);
|
|
22
|
+
|
|
5
23
|
this.host = host;
|
|
6
|
-
this.
|
|
7
|
-
this.args = processArgs;
|
|
8
|
-
this.options = processOptions;
|
|
24
|
+
this.args = [];
|
|
9
25
|
this.sleeping = false;
|
|
10
|
-
this.activitiesCount = 0;
|
|
11
|
-
this.activitiesMap = new Map();
|
|
12
26
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
27
|
+
// 传递给子进程的参数
|
|
28
|
+
this.args.push(JSON.stringify(options.params));
|
|
29
|
+
|
|
30
|
+
const appPath = path.join(__dirname, 'app.js');
|
|
31
|
+
this.child = fork(appPath, this.args, options.processOptions);
|
|
18
32
|
|
|
19
33
|
this.pid = this.child.pid;
|
|
20
34
|
this._init();
|
|
21
35
|
}
|
|
22
36
|
|
|
23
|
-
/**
|
|
24
|
-
* 进程挂起
|
|
25
|
-
*/
|
|
26
|
-
sleep() {
|
|
27
|
-
if (this.activitiesCount) {
|
|
28
|
-
if (this.sleeping) return;
|
|
29
|
-
process.kill(this.pid, 'SIGSTOP');
|
|
30
|
-
this.sleeping = true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 进程唤醒
|
|
36
|
-
*/
|
|
37
|
-
wakeup() {
|
|
38
|
-
if (!this.sleeping) return;
|
|
39
|
-
process.kill(this.pid, 'SIGCONT');
|
|
40
|
-
this.sleeping = false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
37
|
/**
|
|
44
38
|
* 进程初始化
|
|
45
39
|
*/
|
|
46
40
|
_init() {
|
|
47
41
|
this.child.on('message', (data) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-message ${data}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
this.child.on('disconnect', () => {
|
|
46
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-disconnect !`);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
this.child.on('close', (code, signal) => {
|
|
50
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-close code:${code}, signal:${signal}`);
|
|
53
51
|
});
|
|
52
|
+
|
|
54
53
|
this.child.on('exit', (code, signal) => {
|
|
55
|
-
|
|
56
|
-
// this.host.emit('forked_error', code, this.pid);
|
|
57
|
-
// } else {
|
|
58
|
-
// this.host.emit('forked_exit', this.pid);
|
|
59
|
-
// }
|
|
54
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-exit code:${code}, signal:${signal}`);
|
|
60
55
|
});
|
|
56
|
+
|
|
61
57
|
this.child.on('error', (err) => {
|
|
62
|
-
|
|
63
|
-
// this.host.emit('forked_error', err, this.pid);
|
|
58
|
+
Log.coreLogger.error(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-error :${err} !`);
|
|
64
59
|
});
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
/**
|
|
68
|
-
*
|
|
63
|
+
* 进程挂起
|
|
69
64
|
*/
|
|
70
|
-
|
|
71
|
-
if (this.sleeping)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.connectionsCountPlus(params.id);
|
|
75
|
-
this.child.send(params);
|
|
65
|
+
sleep() {
|
|
66
|
+
if (this.sleeping) return;
|
|
67
|
+
process.kill(this.pid, 'SIGSTOP');
|
|
68
|
+
this.sleeping = true;
|
|
76
69
|
}
|
|
77
70
|
|
|
78
71
|
/**
|
|
79
|
-
*
|
|
72
|
+
* 进程唤醒
|
|
80
73
|
*/
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
74
|
+
wakeup() {
|
|
75
|
+
if (!this.sleeping) return;
|
|
76
|
+
process.kill(this.pid, 'SIGCONT');
|
|
77
|
+
this.sleeping = false;
|
|
85
78
|
}
|
|
86
79
|
|
|
87
|
-
/**
|
|
88
|
-
* 连接数-
|
|
89
|
-
*/
|
|
90
|
-
_connectionsCountMinus(id) {
|
|
91
|
-
if (this.activitiesMap.has(id)) {
|
|
92
|
-
this.activitiesCount = (this.activitiesCount > 0) ? (this.activitiesCount - 1) : 0;
|
|
93
|
-
this.activitiesMap.delete(id);
|
|
94
|
-
}
|
|
95
|
-
this.host.connectionsMap[this.pid] = this.activitiesCount;
|
|
96
|
-
}
|
|
97
80
|
}
|
|
98
81
|
|
|
99
82
|
module.exports = ForkProcess;
|