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 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 utils = require('../utils');
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) || utils.isBytecodeClass(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 utils = require('../utils');
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
- if (process.env.NODE_ENV === 'test') {
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) && !utils.isBytecodeClass(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]++}) ${utils.getResolvedFilename(filepath, this.options.baseDir)}`;
270
+ const timingKey = `Require(${this[REQUIRE_COUNT]++}) ${Utils.getResolvedFilename(filepath, this.options.baseDir)}`;
288
271
  this.timing.start(timingKey);
289
- const ret = utils.loadFile(filepath);
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
- if (this.serverScope) files.push(`${filename}.${this.serverScope}_${this.serverEnv}`);
382
+
412
383
  return files;
413
384
  }
414
385
 
415
386
  resolveModule(filepath) {
416
- let fullPath;
387
+ let fullpath;
417
388
  try {
418
- fullPath = require.resolve(filepath);
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
- if (process.env.Ee_TYPESCRIPT !== 'true' && fullPath.endsWith('.ts')) {
428
- return undefined;
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 fullPath;
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 utils = require('../utils');
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' && utils.extensions['.ts'])
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) || utils.isBytecodeClass(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) || utils.isBytecodeClass(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 = utils.loadFile(fullpath);
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) || utils.isBytecodeClass(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
- //console.log('----------------------- appConfig:', appConfig);
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
- filepath = this.resolveModule(path.join(dirpath, 'config/config'));
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-loader] process.env.EE_APP_CONFIG is not invalid JSON: %s', envConfigStr);
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 utilsFn = require('../../utils/function');
6
- const utils = require('../../utils');
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) && !utils.isBytecodeClass(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) || utils.isBytecodeClass(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:loader] Controller loaded: %s', controllerBase);
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 utils.callFn(controller[key], args, controller);
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 = utilsFn.getParamNames(obj[key]);
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 utils.callFn(func, args, this);
117
+ return await Utils.callFn(func, args, this);
118
118
  };
119
119
  for (const key in func) {
120
120
  objectControllerMiddleware[key] = func[key];
@@ -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
 
@@ -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
- let isEncrypted = fs.existsSync(encryptDir);
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('[Appliaction] [initialize] window-all-closed quit');
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:job] ----url: ', url);
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('[error] ', err);
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:main] Env: %s, Type: %s', this.config.env, type);
241
- Log.coreLogger.info('[ee-core:main] App running at: %s', url);
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:httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
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:httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
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, modulePath, processArgs = [], processOptions = {}) {
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.modulePath = modulePath;
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
- this.child = fork(
14
- this.modulePath,
15
- this.args,
16
- this.options
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
- const id = data.id;
49
- this.connectionsCountMinus(id);
50
- delete data.id;
51
- delete data.action;
52
- //this.host.emit('forked_message', {data, id});
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
- // if (code !== 0 && code !== null) {
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
- console.log('forked error: ', err);
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
- send(params) {
71
- if (this.sleeping) {
72
- this.wakeup();
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
- _connectionsCountPlus(id) {
82
- this.activitiesMap.set(id, 1);
83
- this.activitiesCount += 1;
84
- this.host.connectionsMap[this.pid] = this.activitiesCount;
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;