ee-core 2.0.0-beta.2 → 2.0.0-beta.4

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.
Files changed (59) hide show
  1. package/index.js +12 -13
  2. package/{lib → module/app}/application.js +2 -2
  3. package/{lib → module/app}/baseApp.js +3 -3
  4. package/{lib → module/app}/eeApp.js +7 -7
  5. package/module/app/index.js +5 -0
  6. package/{bin → module/bin}/tools.js +1 -1
  7. package/{config → module/config}/config.default.js +2 -3
  8. package/module/const/channel.js +6 -0
  9. package/{core → module/core}/index.js +0 -2
  10. package/{core → module/core}/lib/ee.js +0 -2
  11. package/{core → module/core}/lib/loader/context_loader.js +2 -2
  12. package/{core → module/core}/lib/loader/ee_loader.js +5 -5
  13. package/{core → module/core}/lib/loader/file_loader.js +6 -6
  14. package/{core → module/core}/lib/loader/mixin/addon.js +1 -1
  15. package/{core → module/core}/lib/loader/mixin/config.js +1 -1
  16. package/{core → module/core}/lib/loader/mixin/controller.js +8 -8
  17. package/module/core/lib/utils/base_context_class.js +34 -0
  18. package/module/exception/index.js +75 -6
  19. package/module/httpclient/index.js +2 -2
  20. package/module/jobs/baseJobClass.js +16 -0
  21. package/module/jobs/child/app.js +53 -13
  22. package/module/jobs/child/forkProcess.js +33 -76
  23. package/module/jobs/child/index.js +69 -26
  24. package/module/jobs/childPool/app.js +68 -0
  25. package/module/jobs/childPool/forkProcess.js +81 -0
  26. package/module/jobs/childPool/index.js +71 -0
  27. package/module/jobs/childPool/pool.js +67 -0
  28. package/module/jobs/index.js +5 -54
  29. package/module/jobs/renderer/loadView.js +1 -1
  30. package/module/jobs/unification.js +64 -0
  31. package/module/loader/index.js +36 -14
  32. package/module/log/logger.js +1 -1
  33. package/module/message/childMessage.js +31 -0
  34. package/module/message/index.js +17 -9
  35. package/{utils → module/oldUtils}/index.js +6 -29
  36. package/module/{utils/ps.js → ps/index.js} +45 -0
  37. package/module/service/index.js +34 -0
  38. package/module/socket/httpServer.js +4 -3
  39. package/module/socket/io.js +2 -2
  40. package/module/socket/ipcServer.js +4 -7
  41. package/module/socket/socketClient.js +2 -5
  42. package/module/socket/socketServer.js +4 -6
  43. package/module/storage/jsondbStorage.js +1 -1
  44. package/module/storage/sqliteStorage.js +1 -1
  45. package/{tools → module/tools}/encrypt.js +10 -10
  46. package/{tools → module/tools}/replaceDist.js +6 -6
  47. package/module/utils/helper.js +0 -1
  48. package/module/utils/index.js +2 -36
  49. package/package.json +3 -2
  50. package/module/message/ipcMain.js +0 -160
  51. package/module/message/ipcRender.js +0 -0
  52. /package/{addon → module/addon}/window/index.js +0 -0
  53. /package/{lib → module/app}/appLoader.js +0 -0
  54. /package/{core/lib/utils/base_context_class.js → module/controller/index.js} +0 -0
  55. /package/{core → module/core}/lib/loader/mixin/service.js +0 -0
  56. /package/{core → module/core}/lib/utils/function.js +0 -0
  57. /package/{core → module/core}/lib/utils/index.js +0 -0
  58. /package/{core → module/core}/lib/utils/sequencify.js +0 -0
  59. /package/{core → module/core}/lib/utils/timing.js +0 -0
package/index.js CHANGED
@@ -1,38 +1,31 @@
1
- 'use strict';
2
-
3
1
  /**
4
2
  * @namespace EeCore
5
3
  */
6
-
7
- /**
8
- * @member {Appliaction} EeCore#Appliaction
9
- * @since 1.0.0
10
- */
11
- const Appliaction = require('./lib/application');
4
+ let app;
12
5
 
13
6
  /**
14
7
  * @member {Controller} EeCore#Controller
15
8
  * @since 1.0.0
16
9
  */
17
- const Controller = require('./core/lib/utils/base_context_class');
10
+ const Controller = require('./module/controller');
18
11
 
19
12
  /**
20
13
  * @member {Service} EeCore#Service
21
14
  * @since 1.0.0
22
15
  */
23
- const Service = require('./core/lib/utils/base_context_class');
16
+ const Service = require('./module/service');
24
17
 
25
18
  /**
26
19
  * @member {Storage}
27
20
  * @since 1.0.0
28
21
  */
29
- const Storage = require('./module/storage/index');
22
+ const Storage = require('./module/storage');
30
23
 
31
24
  /**
32
25
  * @member {Utils}
33
26
  * @since 1.0.0
34
27
  */
35
- const Utils = require('./utils/index');
28
+ const Utils = require('./module/oldUtils');
36
29
 
37
30
  /**
38
31
  * @member {Socket}
@@ -41,7 +34,13 @@ const Utils = require('./utils/index');
41
34
  const Socket = require('./module/socket/io');
42
35
 
43
36
  module.exports = {
44
- Appliaction,
37
+ get Appliaction () {
38
+ if (app) {
39
+ return app;
40
+ }
41
+ app = require('./module/app/application');
42
+ return app;
43
+ },
45
44
  Controller,
46
45
  Service,
47
46
  Storage,
@@ -1,3 +1,4 @@
1
+ const Exception = require('../exception');
1
2
  const {app} = require('electron');
2
3
  const path = require('path');
3
4
  const debug = require('debug')('ee-core:Appliaction');
@@ -6,6 +7,7 @@ const EeApp = require('./eeApp');
6
7
 
7
8
  class Appliaction extends EeApp {
8
9
  constructor() {
10
+ Exception.start();
9
11
  const { env } = process;
10
12
  let options = {
11
13
  env: 'prod',
@@ -80,8 +82,6 @@ class Appliaction extends EeApp {
80
82
  await this.ready();
81
83
 
82
84
  await this.createElectronApp();
83
-
84
- await this.catchLog();
85
85
  }
86
86
  }
87
87
 
@@ -3,11 +3,11 @@ const EE_PATH = Symbol.for('ee#eePath');
3
3
  const path = require('path');
4
4
  const EE_LOADER = Symbol.for('ee#loader');
5
5
  const AppLoader = require('./appLoader');
6
- const HttpClient = require('../module/httpclient');
6
+ const HttpClient = require('../httpclient');
7
7
  const HTTPCLIENT = Symbol('EeApplication#httpclient');
8
8
  const LOGGERS = Symbol('EeApplication#loggers');
9
- const Log = require('../module/log');
10
- const Storage = require('../module/storage');
9
+ const Log = require('../log');
10
+ const Storage = require('../storage');
11
11
 
12
12
  class BaseApp extends EeAppCore {
13
13
  constructor (options = {}) {
@@ -8,7 +8,7 @@ const Koa = require('koa');
8
8
  const koaServe = require('koa-static');
9
9
  const https = require('https');
10
10
  const BaseApp = require('./baseApp');
11
- const Log = require('../module/log');
11
+ const Log = require('../log');
12
12
 
13
13
  class EeApp extends BaseApp {
14
14
  constructor(options = {}) {
@@ -51,7 +51,7 @@ class EeApp extends BaseApp {
51
51
  * 启动通信模块
52
52
  */
53
53
  async startSocket () {
54
- const socket = require('../module/socket/start');
54
+ const socket = require('../socket/start');
55
55
  socket(this);
56
56
  }
57
57
 
@@ -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,5 @@
1
+ const App = {
2
+
3
+ }
4
+
5
+ module.exports = App;
@@ -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();
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  const path = require('path');
3
2
 
4
3
  /**
@@ -222,7 +221,7 @@ module.exports = appInfo => {
222
221
  cert: ''
223
222
  },
224
223
  protocol: 'http://',
225
- host: '127.0.0.1',
224
+ host: 'localhost',
226
225
  port: 7071, // 默认端口(如果端口被使用,则随机获取一个)
227
226
  cors: {
228
227
  origin: "*"
@@ -239,7 +238,7 @@ module.exports = appInfo => {
239
238
  /* 主进程加载的地址 */
240
239
  config.mainServer = {
241
240
  protocol: 'http://',
242
- host: '127.0.0.1',
241
+ host: 'localhost',
243
242
  port: 7072, // 默认端口(如果端口被使用,则随机获取一个)
244
243
  options: {},
245
244
  ssl: {
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ process: {
3
+ showException: 'ee#showException',
4
+ sendToMain: 'ee#sendToMain'
5
+ }
6
+ };
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  const EeCore = require('./lib/ee');
4
2
  const EeLoader = require('./lib/loader/ee_loader');
5
3
  const BaseContextClass = require('./lib/utils/base_context_class');
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  const assert = require('assert');
4
2
  const fs = require('fs');
5
3
  const KoaApplication = require('koa');
@@ -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,9 +7,9 @@ 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
- const Ps = require('../../../module/utils/ps');
12
+ const Ps = require('../../../ps');
13
13
 
14
14
  const REQUIRE_COUNT = Symbol('EeLoader#requireCount');
15
15
 
@@ -255,7 +255,7 @@ class EeLoader {
255
255
  if (inject.length === 0) inject = [ this.app ];
256
256
 
257
257
  let ret = this.requireFile(filepath);
258
- if (is.function(ret) && !is.class(ret) && !utils.isBytecodeClass(ret)) {
258
+ if (is.function(ret) && !is.class(ret) && !Utils.isBytecodeClass(ret)) {
259
259
  ret = ret(...inject);
260
260
  }
261
261
  return ret;
@@ -267,9 +267,9 @@ class EeLoader {
267
267
  * @private
268
268
  */
269
269
  requireFile(filepath) {
270
- 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)}`;
271
271
  this.timing.start(timingKey);
272
- const ret = utils.loadFile(filepath);
272
+ const ret = Utils.loadFile(filepath);
273
273
  this.timing.end(timingKey);
274
274
  return ret;
275
275
  }
@@ -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
 
@@ -13,7 +13,7 @@ module.exports = {
13
13
 
14
14
  // 加载ee-core的插件 和 用户插件
15
15
  const directorys = [
16
- path.join(this.options.framework, 'addon'),
16
+ path.join(this.options.framework, 'module', 'addon'),
17
17
  path.join(this.options.baseDir, 'addon'),
18
18
  ]
19
19
  opt = Object.assign({
@@ -102,7 +102,7 @@ module.exports = {
102
102
  this._setConfigMeta(envConfig, '<process.env.EE_APP_CONFIG>');
103
103
  return envConfig;
104
104
  } catch (err) {
105
- 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);
106
106
  }
107
107
  },
108
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];
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * BaseContextClass is a base class that can be extended,
5
+ * it's instantiated in context level,
6
+ * {@link Helper}, {@link Service} is extending it.
7
+ */
8
+ class BaseContextClass {
9
+
10
+ /**
11
+ * @class
12
+ * @param {Context} ctx - context instance
13
+ * @since 1.0.0
14
+ */
15
+ constructor(ctx) {
16
+ /**
17
+ * @member {Application} BaseContextClass#app
18
+ * @since 1.0.0
19
+ */
20
+ this.app = ctx;
21
+ /**
22
+ * @member {Config} BaseContextClass#config
23
+ * @since 1.0.0
24
+ */
25
+ this.config = ctx.config;
26
+ /**
27
+ * @member {Service} BaseContextClass#service
28
+ * @since 1.0.0
29
+ */
30
+ this.service = ctx.service;
31
+ }
32
+ }
33
+
34
+ module.exports = BaseContextClass;
@@ -1,16 +1,85 @@
1
1
  const Log = require('../log');
2
+ const Ps = require('../ps');
3
+ const Channel = require('../const/channel');
2
4
 
3
5
  /**
4
6
  * 捕获异常
5
7
  */
6
8
  exports.start = function() {
7
- process.on('uncaughtException', this.uncaughtExceptionHandler);
9
+ this.uncaughtExceptionHandler();
10
+ this.unhandledRejectionHandler();
8
11
  }
9
12
 
10
- exports.uncaughtExceptionHandler = function(err) {
11
- if (!(err instanceof Error)) {
12
- err = new Error(String(err));
13
+ /**
14
+ * 当进程上抛出异常而没有被捕获时触发该事件,并且使异常静默。
15
+ */
16
+ exports.uncaughtExceptionHandler = function() {
17
+ process.on('uncaughtException', function(err) {
18
+ if (!(err instanceof Error)) {
19
+ err = new Error(String(err));
20
+ }
21
+
22
+ if (err.name === 'Error') {
23
+ err.name = 'unhandledExceptionError';
24
+ }
25
+
26
+ Log.coreLogger.error(err);
27
+
28
+ devError(err);
29
+ });
30
+ }
31
+
32
+ /**
33
+ * 当进程上抛出异常而没有被捕获时触发该事件。
34
+ */
35
+ exports.uncaughtExceptionMonitorHandler = function() {
36
+ // process.on('uncaughtExceptionMonitor', function(err, origin) {
37
+ // if (!(err instanceof Error)) {
38
+ // err = new Error(String(err));
39
+ // }
40
+
41
+ // Log.coreLogger.error('uncaughtExceptionMonitor:',err);
42
+ // });
43
+ }
44
+
45
+ /**
46
+ * 当promise中reject的异常在同步任务中没有使用catch捕获就会触发该事件,
47
+ * 即便是在异步情况下使用了catch也会触发该事件
48
+ */
49
+ exports.unhandledRejectionHandler = function() {
50
+ process.on('unhandledRejection', function(err) {
51
+ if (!(err instanceof Error)) {
52
+ const newError = new Error(String(err));
53
+ // err maybe an object, try to copy the name, message and stack to the new error instance
54
+ if (err) {
55
+ if (err.name) newError.name = err.name;
56
+ if (err.message) newError.message = err.message;
57
+ if (err.stack) newError.stack = err.stack;
58
+ }
59
+ err = newError;
60
+ }
61
+ if (err.name === 'Error') {
62
+ err.name = 'unhandledRejectionError';
63
+ }
64
+
65
+ Log.coreLogger.error(err);
66
+
67
+ devError(err);
68
+ });
69
+ }
70
+
71
+ /**
72
+ * 如果是子进程,发送错误到主进程控制台
73
+ */
74
+ function devError (err) {
75
+ if (Ps.isForkedChild() && Ps.isDev()) {
76
+ let msgChannel = Channel.process.showException;
77
+ let errTips = (err && typeof err == 'object') ? err.toString() : '';
78
+ errTips += ' Error !!! Please See file ee-core.log or ee-error-xxx.log for details !'
79
+ let message = {
80
+ channel: msgChannel,
81
+ data: errTips
82
+ }
83
+ process.send(message);
13
84
  }
14
-
15
- Log.coreLogger.error(err);
16
85
  }
@@ -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] [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] [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,16 @@
1
+ /**
2
+ * BaseJobClass
3
+ */
4
+ class BaseJobClass {
5
+
6
+ /**
7
+ * @class
8
+ * @param {Object} params - job基础类
9
+ * @since 1.0.0
10
+ */
11
+ constructor(params = {}) {
12
+ // todo
13
+ }
14
+ }
15
+
16
+ module.exports = BaseJobClass;
@@ -1,23 +1,63 @@
1
- const Exception = require('ee-core/module/exception');
2
- Exception.start();
3
1
 
4
- const Loader = require('ee-core/module/loader');
5
- const Log = require('ee-core/module/log');
2
+ const is = require('is-type-of');
3
+ let Exception;
4
+ let Loader;
5
+ let Log;
6
+ let UtilsCore;
7
+
8
+ // 开发环境下,ee-core是soft link
9
+ if (__dirname.indexOf("node_modules") == -1) {
10
+ Exception = require('../../exception');
11
+ Loader = require('../../loader');
12
+ Log = require('../../log');
13
+ UtilsCore = require('../../core/lib/utils');
14
+ } else {
15
+ Exception = require('ee-core/module/exception');
16
+ Loader = require('ee-core/module/loader');
17
+ Log = require('ee-core/module/log');
18
+ UtilsCore = require('../../core/lib/utils');
19
+ }
20
+
21
+ Exception.start();
6
22
 
7
23
  class ChildApp {
8
24
  constructor() {
9
- const args = process.argv[2];
10
- this.opt = args ? JSON.parse(args) : {};
25
+ this._initEvents();
26
+ }
27
+
28
+ /**
29
+ * 初始化事件监听
30
+ */
31
+ _initEvents() {
32
+ process.on('message', this._handleMessage.bind(this));
33
+ process.on('exit', (code) => {
34
+ Log.coreLogger.info(`[ee-core] [jobs/child] received a exit from main-process, code:${code}, pid:${process.pid}`);
35
+ });
36
+ }
37
+
38
+ /**
39
+ * 监听消息
40
+ */
41
+ _handleMessage(m) {
42
+ this.run(m);
43
+ Log.coreLogger.info(`[ee-core] [jobs/child] received a message from main-process, message: ${JSON.stringify(m)}`);
11
44
  }
12
45
 
13
- run () {
14
- Log.info('[child-process] run');
15
-
16
- const jobFile = this.opt.jobPath;
46
+ /**
47
+ * 运行脚本
48
+ */
49
+ run(msg = {}) {
50
+ let filepath = msg.jobPath;
51
+ let params = msg.jobParams;
17
52
 
18
- Loader.loadJobFile(jobFile);
53
+ let mod = Loader.loadJsFile(filepath);
54
+ if (is.class(mod) || UtilsCore.isBytecodeClass(mod)) {
55
+ let jobClass = new mod(params);
56
+ jobClass.handle();
57
+ } else if (is.function(mod)) {
58
+ mod(params);
59
+ }
19
60
  }
20
61
  }
21
62
 
22
- const app = new ChildApp()
23
- app.run();
63
+ new ChildApp();