ee-core 2.10.2 → 2.11.0

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.
@@ -1,4 +1,5 @@
1
1
  const { BrowserWindow } = require('electron');
2
+ const extend = require('../../utils/extend');
2
3
 
3
4
  /**
4
5
  * 窗口插件
@@ -23,9 +24,8 @@ class WinAddon {
23
24
  // if (this.windowContentsIdMap.hasOwnProperty(name)) {
24
25
  // throw new Error(`[addon] [window] Name: ${name} already exists!`);
25
26
  // }
26
-
27
- // [todo] 使用 extend, 避免多维对象被覆盖
28
- const options = Object.assign({
27
+
28
+ const options = extend(true, {}, {
29
29
  x: 10,
30
30
  y: 10,
31
31
  width: 980,
@@ -3,31 +3,22 @@
3
3
  /**
4
4
  * BaseContextClass is a base class that can be extended,
5
5
  * it's instantiated in context level,
6
- * {@link Helper}, {@link Service} is extending it.
7
6
  */
8
7
  class BaseContextClass {
9
8
 
10
9
  /**
11
10
  * @class
12
11
  * @param {Context} ctx - context instance
13
- * @since 1.0.0
12
+ * @since 1.1.0
14
13
  */
15
14
  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;
15
+
16
+ // todo 兼容旧版本,后续废弃ctx
17
+ if (typeof ctx === 'object') {
18
+ this.app = ctx;
19
+ this.config = ctx.config;
20
+ this.service = ctx.service;
21
+ }
31
22
  }
32
23
  }
33
24
 
@@ -3,31 +3,22 @@
3
3
  /**
4
4
  * BaseContextClass is a base class that can be extended,
5
5
  * it's instantiated in context level,
6
- * {@link Helper}, {@link Service} is extending it.
7
6
  */
8
7
  class BaseContextClass {
9
8
 
10
9
  /**
11
10
  * @class
12
11
  * @param {Context} ctx - context instance
13
- * @since 1.0.0
12
+ * @since 1.1.0
14
13
  */
15
14
  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;
15
+
16
+ // todo 兼容旧版本,后续废弃ctx
17
+ if (typeof ctx === 'object') {
18
+ this.app = ctx;
19
+ this.config = ctx.config;
20
+ this.service = ctx.service;
21
+ }
31
22
  }
32
23
  }
33
24
 
@@ -95,7 +95,8 @@ class SpawnProcess {
95
95
  pid: this.pid
96
96
  }
97
97
  this.host.emitter.emit(Channel.events.childProcessExit, data);
98
- Log.coreLogger.info(`[ee-core] [corss/process] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
98
+ // Child process closed: The child process was killed externally or an internal error caused the application to stop, resulting in the application exiting
99
+ Log.coreLogger.info(`[ee-core] [corss/process] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}, cmd:${cmdPath}, args: ${cmdArgs}`);
99
100
  this._exitElectron();
100
101
  });
101
102
 
package/jobs/child/app.js CHANGED
@@ -11,6 +11,7 @@ const commands = ['run'];
11
11
  class ChildApp {
12
12
  constructor() {
13
13
  this._initEvents();
14
+ this.jobMap = new Map();
14
15
  }
15
16
 
16
17
  /**
@@ -43,15 +44,20 @@ class ChildApp {
43
44
  * 运行脚本
44
45
  */
45
46
  run(msg = {}) {
46
- let filepath = msg.jobPath;
47
- let params = msg.jobParams;
48
-
49
- let mod = Loader.loadJsFile(filepath);
47
+ const {jobPath, jobParams, jobFunc, jobFuncParams} = msg;
48
+ let mod = Loader.loadJsFile(jobPath);
50
49
  if (is.class(mod) || UtilsCore.isBytecodeClass(mod)) {
51
- let jobClass = new mod(params);
52
- jobClass.handle();
50
+ if (!this.jobMap.has(jobPath)) {
51
+ const instance = new mod(...jobParams);
52
+ instance.handle(...jobParams);
53
+ this.jobMap.set(jobPath, instance);
54
+ } else {
55
+ const instance = this.jobMap.get(jobPath);
56
+ instance[jobFunc](...jobFuncParams);
57
+ }
58
+
53
59
  } else if (is.function(mod)) {
54
- mod(params);
60
+ mod(jobParams);
55
61
  }
56
62
  }
57
63
  }
@@ -6,6 +6,7 @@ const Log = require('../../log');
6
6
  const Ps = require('../../ps');
7
7
  const Channel = require('../../const/channel');
8
8
  const Helper = require('../../utils/helper');
9
+ const Loader = require('../../loader');
9
10
 
10
11
  class ForkProcess {
11
12
  constructor(host, opt = {}) {
@@ -98,7 +99,7 @@ class ForkProcess {
98
99
  /**
99
100
  * 分发任务
100
101
  */
101
- dispatch(cmd, jobPath = '', params = {}) {
102
+ dispatch(cmd, jobPath = '', ...params) {
102
103
  // 消息对象
103
104
  const mid = Helper.getRandomString();
104
105
  let msg = {
@@ -113,6 +114,24 @@ class ForkProcess {
113
114
  this.child.send(msg);
114
115
  }
115
116
 
117
+ /**
118
+ * 调用job的方法
119
+ */
120
+ callFunc(jobPath = '', funcName = '', ...params) {
121
+ jobPath = Loader.getFullpath(jobPath);
122
+
123
+ // 消息对象
124
+ const mid = Helper.getRandomString();
125
+ let msg = {
126
+ mid,
127
+ cmd:'run',
128
+ jobPath,
129
+ jobFunc: funcName,
130
+ jobFuncParams: params
131
+ }
132
+ this.child.send(msg);
133
+ }
134
+
116
135
  /**
117
136
  * kill
118
137
  */
@@ -6,7 +6,7 @@ class ChildMessage {
6
6
  }
7
7
 
8
8
  /**
9
- * 向主进程发消息
9
+ * 向主进程发消息 for ChildJob 实例
10
10
  */
11
11
  sendToMain(eventName, params = {}) {
12
12
  let receiver = Channel.receiver.childJob;
@@ -14,7 +14,7 @@ class ChildMessage {
14
14
  }
15
15
 
16
16
  /**
17
- * 向主进程发消息
17
+ * 向主进程发消息 for task 实例
18
18
  */
19
19
  send(eventName, params = {}, receiver) {
20
20
  let eventReceiver = receiver || Channel.receiver.forkProcess;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "2.10.2",
3
+ "version": "2.11.0",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,32 +2,22 @@
2
2
 
3
3
  /**
4
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
5
  */
8
6
  class BaseContextClass {
9
7
 
10
8
  /**
11
9
  * @class
12
10
  * @param {Context} ctx - context instance
13
- * @since 1.0.0
11
+ * @since 1.1.0
14
12
  */
15
13
  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;
14
+
15
+ // todo 兼容旧版本,后续废弃ctx
16
+ if (typeof ctx === 'object') {
17
+ this.app = ctx;
18
+ this.config = ctx.config;
19
+ this.service = ctx.service;
20
+ }
31
21
  }
32
22
  }
33
23