ee-core 2.12.0 → 4.0.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.
Files changed (159) hide show
  1. package/app/application.d.ts +5 -0
  2. package/app/application.js +31 -0
  3. package/app/boot.d.ts +5 -0
  4. package/app/boot.js +74 -0
  5. package/app/dir.d.ts +1 -0
  6. package/app/dir.js +27 -0
  7. package/app/events.d.ts +14 -0
  8. package/app/events.js +56 -0
  9. package/app/index.d.ts +2 -0
  10. package/app/index.js +7 -0
  11. package/config/config_loader.d.ts +13 -0
  12. package/config/config_loader.js +19 -23
  13. package/config/default_config.d.ts +95 -0
  14. package/config/default_config.js +111 -0
  15. package/config/index.d.ts +28 -0
  16. package/config/index.js +20 -37
  17. package/const/channel.d.ts +16 -0
  18. package/const/channel.js +26 -16
  19. package/controller/controller_loader.d.ts +9 -0
  20. package/controller/controller_loader.js +78 -0
  21. package/controller/index.d.ts +2 -0
  22. package/controller/index.js +18 -19
  23. package/core/index.d.ts +2 -0
  24. package/core/index.js +6 -5
  25. package/core/loader/file_loader.d.ts +66 -0
  26. package/core/{lib/loader → loader}/file_loader.js +39 -156
  27. package/core/utils/index.d.ts +12 -0
  28. package/core/utils/index.js +83 -0
  29. package/core/utils/timing.d.ts +22 -0
  30. package/core/{lib/utils → utils}/timing.js +3 -2
  31. package/cross/cross.d.ts +19 -0
  32. package/cross/cross.js +152 -0
  33. package/cross/crossProcess.d.ts +29 -0
  34. package/cross/{spawnProcess.js → crossProcess.js} +36 -53
  35. package/cross/index.d.ts +2 -0
  36. package/cross/index.js +6 -181
  37. package/electron/app/index.d.ts +5 -0
  38. package/electron/app/index.js +38 -54
  39. package/electron/index.d.ts +3 -0
  40. package/electron/index.js +13 -17
  41. package/electron/window/index.d.ts +6 -0
  42. package/electron/window/index.js +260 -65
  43. package/exception/index.d.ts +9 -0
  44. package/exception/index.js +42 -54
  45. package/html/index.d.ts +1 -0
  46. package/html/index.js +7 -10
  47. package/index.d.ts +2 -0
  48. package/index.js +4 -52
  49. package/jobs/child/app.d.ts +1 -0
  50. package/jobs/child/app.js +10 -10
  51. package/jobs/child/index.d.ts +13 -0
  52. package/jobs/child/index.js +14 -11
  53. package/jobs/child/jobProcess.d.ts +16 -0
  54. package/jobs/child/{forkProcess.js → jobProcess.js} +31 -62
  55. package/jobs/child-pool/index.d.ts +26 -0
  56. package/jobs/child-pool/index.js +25 -48
  57. package/jobs/index.d.ts +3 -0
  58. package/jobs/index.js +2 -4
  59. package/jobs/load-balancer/algorithm/index.d.ts +4 -0
  60. package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
  61. package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
  62. package/jobs/load-balancer/algorithm/random.d.ts +2 -0
  63. package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
  64. package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
  65. package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
  66. package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
  67. package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
  68. package/jobs/load-balancer/consts.d.ts +8 -0
  69. package/jobs/load-balancer/index.d.ts +96 -0
  70. package/jobs/load-balancer/scheduler.d.ts +16 -0
  71. package/loader/index.d.ts +9 -0
  72. package/loader/index.js +73 -143
  73. package/log/index.d.ts +5 -0
  74. package/log/index.js +74 -57
  75. package/log/logger.d.ts +2 -0
  76. package/log/logger.js +75 -80
  77. package/message/childMessage.d.ts +10 -0
  78. package/message/childMessage.js +15 -25
  79. package/message/index.d.ts +3 -0
  80. package/message/index.js +7 -16
  81. package/package.json +8 -2
  82. package/ps/index.d.ts +37 -0
  83. package/ps/index.js +135 -238
  84. package/socket/httpServer.d.ts +8 -0
  85. package/socket/httpServer.js +55 -45
  86. package/socket/index.d.ts +10 -0
  87. package/socket/index.js +52 -69
  88. package/socket/ipcServer.d.ts +9 -0
  89. package/socket/ipcServer.js +87 -94
  90. package/socket/socketServer.d.ts +10 -0
  91. package/socket/socketServer.js +37 -25
  92. package/storage/index.d.ts +5 -0
  93. package/storage/index.js +5 -37
  94. package/storage/sqliteStorage.d.ts +16 -0
  95. package/storage/sqliteStorage.js +20 -20
  96. package/tsconfig.json +14 -0
  97. package/utils/extend.d.ts +2 -0
  98. package/utils/extend.js +10 -5
  99. package/utils/helper.d.ts +14 -0
  100. package/utils/helper.js +39 -53
  101. package/utils/index.d.ts +10 -0
  102. package/utils/index.js +47 -40
  103. package/utils/ip.d.ts +2 -0
  104. package/utils/ip.js +5 -45
  105. package/utils/is.d.ts +14 -0
  106. package/utils/is.js +107 -141
  107. package/utils/json.d.ts +5 -0
  108. package/utils/json.js +15 -7
  109. package/utils/pargv.d.ts +3 -0
  110. package/utils/pargv.js +5 -1
  111. package/utils/port/index.d.ts +1 -0
  112. package/utils/{get-port → port}/index.js +4 -26
  113. package/utils/wrap.d.ts +4 -0
  114. package/utils/wrap.js +8 -3
  115. package/addon/index.js +0 -35
  116. package/addon/window/index.js +0 -99
  117. package/bin/tools.js +0 -8
  118. package/config/cache.js +0 -62
  119. package/config/config.default.js +0 -331
  120. package/const/index.js +0 -9
  121. package/controller/baseContextClass.js +0 -25
  122. package/core/lib/ee.js +0 -216
  123. package/core/lib/loader/context_loader.js +0 -106
  124. package/core/lib/loader/ee_loader.js +0 -435
  125. package/core/lib/loader/mixin/addon.js +0 -32
  126. package/core/lib/loader/mixin/config.js +0 -130
  127. package/core/lib/loader/mixin/controller.js +0 -125
  128. package/core/lib/loader/mixin/service.js +0 -28
  129. package/core/lib/utils/base_context_class.js +0 -34
  130. package/core/lib/utils/function.js +0 -30
  131. package/core/lib/utils/index.js +0 -133
  132. package/core/lib/utils/sequencify.js +0 -59
  133. package/ee/appLoader.js +0 -48
  134. package/ee/application.js +0 -101
  135. package/ee/baseApp.js +0 -99
  136. package/ee/eeApp.js +0 -406
  137. package/ee/index.js +0 -58
  138. package/electron/window/winState.js +0 -186
  139. package/httpclient/index.js +0 -161
  140. package/jobs/baseJobClass.js +0 -16
  141. package/jobs/renderer/index.js +0 -141
  142. package/jobs/renderer/loadView.js +0 -41
  143. package/jobs/unification.js +0 -64
  144. package/main/index.js +0 -57
  145. package/old-utils/index.js +0 -91
  146. package/services/baseContextClass.js +0 -24
  147. package/services/index.js +0 -41
  148. package/socket/io.js +0 -28
  149. package/storage/jsondb/adapters/Base.js +0 -23
  150. package/storage/jsondb/adapters/FileSync.js +0 -64
  151. package/storage/jsondb/main.js +0 -55
  152. package/storage/jsondbStorage.js +0 -196
  153. package/utils/co.js +0 -237
  154. package/utils/copyto.js +0 -161
  155. package/utils/depd/index.js +0 -538
  156. package/utils/depd/lib/browser/index.js +0 -77
  157. package/utils/get-port/index.d.ts +0 -64
  158. package/utils/time/index.js +0 -20
  159. package/utils/time/ms.js +0 -162
@@ -0,0 +1,13 @@
1
+ import EventEmitter = require("events");
2
+ import { JobProcess } from "./jobProcess";
3
+ export declare class ChildJob extends EventEmitter<[never]> {
4
+ constructor();
5
+ jobs: {};
6
+ config: any;
7
+ _initEvents(): void;
8
+ exec(filepath: string, params?: {}, opt?: {}): JobProcess;
9
+ createProcess(opt?: {}): JobProcess;
10
+ getPids(): string[];
11
+ execPromise(filepath: string, params?: {}, opt?: {}): Promise<JobProcess>;
12
+ }
13
+
@@ -1,8 +1,9 @@
1
1
  const EventEmitter = require('events');
2
- const ForkProcess = require('./forkProcess');
3
- const Loader = require('../../loader');
4
- const Channel = require('../../const/channel');
5
- const Conf = require('../../config/cache');
2
+ const { JobProcess } = require('./jobProcess');
3
+ const { getFullpath } = require('../../loader');
4
+ const { Events } = require('../../const/channel');
5
+ const { getConfig } = require('../../config');
6
+ const { extend } = require('../../utils/extend');
6
7
 
7
8
  class ChildJob extends EventEmitter {
8
9
 
@@ -11,7 +12,7 @@ class ChildJob extends EventEmitter {
11
12
  this.jobs = {};
12
13
  this.config = {};
13
14
 
14
- const cfg = Conf.getValue('jobs');
15
+ const cfg = getConfig().jobs;
15
16
  if (cfg) {
16
17
  this.config = cfg;
17
18
  }
@@ -23,10 +24,10 @@ class ChildJob extends EventEmitter {
23
24
  * 初始化监听
24
25
  */
25
26
  _initEvents() {
26
- this.on(Channel.events.childProcessExit, (data) => {
27
+ this.on(Events.childProcessExit, (data) => {
27
28
  delete this.jobs[data.pid];
28
29
  });
29
- this.on(Channel.events.childProcessError, (data) => {
30
+ this.on(Events.childProcessError, (data) => {
30
31
  delete this.jobs[data.pid];
31
32
  });
32
33
  }
@@ -35,7 +36,7 @@ class ChildJob extends EventEmitter {
35
36
  * 执行一个job文件
36
37
  */
37
38
  exec(filepath, params = {}, opt = {}) {
38
- const jobPath = Loader.getFullpath(filepath);
39
+ const jobPath = getFullpath(filepath);
39
40
  const proc = this.createProcess(opt);
40
41
  const cmd = 'run';
41
42
  proc.dispatch(cmd, jobPath, params);
@@ -47,12 +48,12 @@ class ChildJob extends EventEmitter {
47
48
  * 创建子进程
48
49
  */
49
50
  createProcess(opt = {}) {
50
- let options = Object.assign({
51
+ const options = extend(true, {
51
52
  processArgs: {
52
53
  type: 'childJob'
53
54
  }
54
55
  }, opt);
55
- const proc = new ForkProcess(this, options);
56
+ const proc = new JobProcess(this, options);
56
57
  if (!proc) {
57
58
  let errorMessage = `[ee-core] [jobs/child] Failed to obtain the child process !`
58
59
  throw new Error(errorMessage);
@@ -79,4 +80,6 @@ class ChildJob extends EventEmitter {
79
80
 
80
81
  }
81
82
 
82
- module.exports = ChildJob;
83
+ module.exports = {
84
+ ChildJob
85
+ };
@@ -0,0 +1,16 @@
1
+ import { EventEmitter } from "events";
2
+ import { ChildProcess } from "child_process";
3
+ declare export class JobProcess {
4
+ constructor(host: any, opt?: {});
5
+ emitter: EventEmitter<[never]>;
6
+ host: any;
7
+ args: string[];
8
+ sleeping: boolean;
9
+ child: ChildProcess;
10
+ pid: number;
11
+ _init(): void;
12
+ _eventEmit(m: any): void;
13
+ dispatch(cmd: string, jobPath?: string, ...params: any[]): void;
14
+ callFunc(jobPath?: string, funcName?: string, ...params: any[]): void;
15
+ kill(timeout?: number): void;
16
+ }
@@ -1,29 +1,29 @@
1
1
  const path = require('path');
2
2
  const EventEmitter = require('events');
3
- const { fork } = require('child_process');
4
3
  const serialize = require('serialize-javascript');
5
- const Log = require('../../log');
6
- const Ps = require('../../ps');
7
- const Channel = require('../../const/channel');
8
- const Helper = require('../../utils/helper');
9
- const Loader = require('../../loader');
10
- const extend = require('../../utils/extend');
11
-
12
- class ForkProcess {
4
+ const { fork } = require('child_process');
5
+ const { coreLogger } = require('../../log');
6
+ const { getBaseDir, isPackaged, allEnv } = require('../../ps');
7
+ const { Processes, Events, Receiver } = require('../../const/channel');
8
+ const { getRandomString } = require('../../utils/helper');
9
+ const { getFullpath } = require('../../loader');
10
+ const { extend } = require('../../utils/extend');
11
+
12
+ class JobProcess {
13
13
  constructor(host, opt = {}) {
14
14
 
15
- let cwd = Ps.getHomeDir();
16
- let appPath = path.join(__dirname, 'app.js');
17
- if (Ps.isPackaged()) {
15
+ let cwd = getBaseDir();
16
+ const appPath = path.join(__dirname, 'app.js');
17
+ if (isPackaged()) {
18
18
  // todo fork的cwd目录为什么要在app.asar外 ?
19
- cwd = path.join(Ps.getHomeDir(), '..');
19
+ cwd = path.join(getBaseDir(), '..');
20
20
  }
21
21
 
22
- let options = extend(true,{
22
+ const options = extend(true, {
23
23
  processArgs: {},
24
24
  processOptions: {
25
25
  cwd: cwd,
26
- env: Ps.allEnv(),
26
+ env: allEnv(),
27
27
  stdio: 'ignore' // pipe
28
28
  }
29
29
  }, opt);
@@ -41,22 +41,19 @@ class ForkProcess {
41
41
  this._init();
42
42
  }
43
43
 
44
- /**
45
- * 初始化事件监听
46
- */
47
44
  _init() {
48
45
  const { messageLog } = this.host.config;
49
46
  this.child.on('message', (m) => {
50
47
  if (messageLog == true) {
51
- Log.coreLogger.info(`[ee-core] [jobs/child] received a message from child-process, message: ${serialize(m)}`);
48
+ coreLogger.info(`[ee-core] [jobs/child] received a message from child-process, message: ${serialize(m)}`);
52
49
  }
53
50
 
54
- if (m.channel == Channel.process.showException) {
55
- Log.coreLogger.error(`${m.data}`);
51
+ if (m.channel == Processes.showException) {
52
+ coreLogger.error(`${m.data}`);
56
53
  }
57
54
 
58
55
  // 收到子进程消息,转发到 event
59
- if (m.channel == Channel.process.sendToMain) {
56
+ if (m.channel == Processes.sendToMain) {
60
57
  this._eventEmit(m);
61
58
  }
62
59
  });
@@ -65,28 +62,25 @@ class ForkProcess {
65
62
  let data = {
66
63
  pid: this.pid
67
64
  }
68
- this.host.emit(Channel.events.childProcessExit, data);
69
- Log.coreLogger.info(`[ee-core] [jobs/child] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
65
+ this.host.emit(Events.childProcessExit, data);
66
+ coreLogger.info(`[ee-core] [jobs/child] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
70
67
  });
71
68
 
72
69
  this.child.on('error', (err) => {
73
70
  let data = {
74
71
  pid: this.pid
75
72
  }
76
- this.host.emit(Channel.events.childProcessError, data);
77
- Log.coreLogger.error(`[ee-core] [jobs/child] received a error from child-process, error: ${err}, pid:${this.pid}`);
73
+ this.host.emit(Events.childProcessError, data);
74
+ coreLogger.error(`[ee-core] [jobs/child] received a error from child-process, error: ${err}, pid:${this.pid}`);
78
75
  });
79
76
  }
80
77
 
81
- /**
82
- * event emit
83
- */
84
78
  _eventEmit(m) {
85
79
  switch (m.eventReceiver) {
86
- case Channel.receiver.forkProcess:
80
+ case Receiver.forkProcess:
87
81
  this.emitter.emit(m.event, m.data);
88
82
  break;
89
- case Channel.receiver.childJob:
83
+ case Receiver.childJob:
90
84
  this.host.emit(m.event, m.data);
91
85
  break;
92
86
  default:
@@ -96,12 +90,9 @@ class ForkProcess {
96
90
  }
97
91
  }
98
92
 
99
- /**
100
- * 分发任务
101
- */
102
93
  dispatch(cmd, jobPath = '', ...params) {
103
94
  // 消息对象
104
- const mid = Helper.getRandomString();
95
+ const mid = getRandomString();
105
96
  let msg = {
106
97
  mid,
107
98
  cmd,
@@ -114,14 +105,11 @@ class ForkProcess {
114
105
  this.child.send(msg);
115
106
  }
116
107
 
117
- /**
118
- * 调用job的方法
119
- */
120
108
  callFunc(jobPath = '', funcName = '', ...params) {
121
- jobPath = Loader.getFullpath(jobPath);
109
+ jobPath = getFullpath(jobPath);
122
110
 
123
111
  // 消息对象
124
- const mid = Helper.getRandomString();
112
+ const mid = getRandomString();
125
113
  let msg = {
126
114
  mid,
127
115
  cmd:'run',
@@ -132,9 +120,6 @@ class ForkProcess {
132
120
  this.child.send(msg);
133
121
  }
134
122
 
135
- /**
136
- * kill
137
- */
138
123
  kill(timeout = 1000) {
139
124
  this.child.kill('SIGINT');
140
125
  setTimeout(() => {
@@ -142,24 +127,8 @@ class ForkProcess {
142
127
  this.child.kill('SIGKILL');
143
128
  }, timeout)
144
129
  }
145
-
146
- /**
147
- * sleep (仅Unix平台)
148
- */
149
- sleep() {
150
- if (this.sleeping) return;
151
- process.kill(this.pid, 'SIGSTOP');
152
- this.sleeping = true;
153
- }
154
-
155
- /**
156
- * wakeup (仅Unix平台)
157
- */
158
- wakeup() {
159
- if (!this.sleeping) return;
160
- process.kill(this.pid, 'SIGCONT');
161
- this.sleeping = false;
162
- }
163
130
  }
164
131
 
165
- module.exports = ForkProcess;
132
+ module.exports = {
133
+ JobProcess
134
+ };
@@ -0,0 +1,26 @@
1
+ import EventEmitter = require("events");
2
+ import LoadBalancer = require("../load-balancer");
3
+ export declare class ChildPoolJob extends EventEmitter<[never]> {
4
+ constructor(opt?: {});
5
+ config: any;
6
+ boundMap: Map<any, any>;
7
+ children: {};
8
+ min: number;
9
+ max: number;
10
+ strategy: string;
11
+ weights: any[];
12
+ LB: LoadBalancer;
13
+ _initEvents(): void;
14
+ _removeChild(pid: any): void;
15
+ create(number?: number): Promise<string[]>;
16
+ _childCreated(childProcess: any): void;
17
+ run(filepath: any, params?: {}): any;
18
+ runPromise(filepath: any, params?: {}): Promise<any>;
19
+ getBoundChild(boundId: any): any;
20
+ getChildByPid(pid: any): any;
21
+ getChild(): any;
22
+ getPids(): string[];
23
+ // kill all
24
+ // type: sequence | parallel
25
+ killAll(type?: string): void;
26
+ }
@@ -1,10 +1,10 @@
1
1
  const EventEmitter = require('events');
2
2
  const LoadBalancer = require('../load-balancer');
3
- const Loader = require('../../loader');
4
- const ForkProcess = require('../child/forkProcess');
5
- const Channel = require('../../const/channel');
6
- const Helper = require('../../utils/helper');
7
- const Conf = require('../../config/cache');
3
+ const { getFullpath } = require('../../loader');
4
+ const { JobProcess } = require('../child/jobProcess');
5
+ const { Events } = require('../../const/channel');
6
+ const { validValue } = require('../../utils/helper');
7
+ const { getConfig } = require('../../config');
8
8
 
9
9
  class ChildPoolJob extends EventEmitter {
10
10
 
@@ -21,7 +21,7 @@ class ChildPoolJob extends EventEmitter {
21
21
  this.max = 6;
22
22
  this.strategy = 'polling';
23
23
  this.weights = new Array(this.max).fill().map((v, i) => {
24
- let w = Helper.validValue(options.weights[i]) ? options.weights[i] : 1
24
+ let w = validValue(options.weights[i]) ? options.weights[i] : 1
25
25
  return w;
26
26
  });
27
27
 
@@ -31,7 +31,7 @@ class ChildPoolJob extends EventEmitter {
31
31
  }
32
32
  this.LB = new LoadBalancer(lbOpt);
33
33
 
34
- const cfg = Conf.getValue('jobs');
34
+ const cfg = getConfig().jobs;
35
35
  if (cfg) {
36
36
  this.config = cfg;
37
37
  }
@@ -39,21 +39,15 @@ class ChildPoolJob extends EventEmitter {
39
39
  this._initEvents();
40
40
  }
41
41
 
42
- /**
43
- * 初始化监听
44
- */
45
42
  _initEvents() {
46
- this.on(Channel.events.childProcessExit, (data) => {
43
+ this.on(Events.childProcessExit, (data) => {
47
44
  this._removeChild(data.pid);
48
45
  });
49
- this.on(Channel.events.childProcessError, (data) => {
46
+ this.on(Events.childProcessError, (data) => {
50
47
  this._removeChild(data.pid);
51
48
  });
52
49
  }
53
-
54
- /**
55
- * 移除对象
56
- */
50
+
57
51
  _removeChild(pid) {
58
52
  const length = Object.keys(this.children).length;
59
53
  const lbOpt = {
@@ -63,10 +57,7 @@ class ChildPoolJob extends EventEmitter {
63
57
  this.LB.del(lbOpt);
64
58
  delete this.children[pid];
65
59
  }
66
-
67
- /**
68
- * 创建一个池子
69
- */
60
+
70
61
  async create(number = 3) {
71
62
  if (number < 0 || number > this.max) {
72
63
  throw new Error(`[ee-core] [jobs/child-pool] The number is invalid !`);
@@ -87,7 +78,7 @@ class ChildPoolJob extends EventEmitter {
87
78
  }
88
79
  }, {});
89
80
  for (let i = 1; i <= number; i++) {
90
- let task = new ForkProcess(this, options);
81
+ let task = new JobProcess(this, options);
91
82
  this._childCreated(task);
92
83
  }
93
84
 
@@ -96,9 +87,7 @@ class ChildPoolJob extends EventEmitter {
96
87
  return pids;
97
88
  }
98
89
 
99
- /**
100
- * 子进程创建后处理
101
- */
90
+ // Post creation processing of child processes
102
91
  _childCreated(childProcess) {
103
92
  let pid = childProcess.pid;
104
93
  this.children[pid] = childProcess;
@@ -111,27 +100,21 @@ class ChildPoolJob extends EventEmitter {
111
100
  this.LB.add(lbTask);
112
101
  }
113
102
 
114
- /**
115
- * 执行一个job文件
116
- */
103
+ // Execute a job file
117
104
  run(filepath, params = {}) {
118
- const jobPath = Loader.getFullpath(filepath);
105
+ const jobPath = getFullpath(filepath);
119
106
  const childProcess = this.getChild();
120
107
  childProcess.dispatch('run', jobPath, params);
121
108
 
122
109
  return childProcess;
123
110
  }
124
111
 
125
- /**
126
- * 异步执行一个job文件
127
- */
112
+ // Asynchronous execution of a job file
128
113
  async runPromise(filepath, params = {}) {
129
114
  return this.run(filepath, params);
130
115
  }
131
116
 
132
- /**
133
- * 获取绑定的进程对象
134
- */
117
+ // Get the bound process object
135
118
  getBoundChild(boundId) {
136
119
  let proc;
137
120
  const boundPid = this.boundMap.get(boundId);
@@ -147,17 +130,13 @@ class ChildPoolJob extends EventEmitter {
147
130
  return proc;
148
131
  }
149
132
 
150
- /**
151
- * 通过pid获取一个子进程对象
152
- */
133
+ // Retrieve a sub process object through PID
153
134
  getChildByPid(pid) {
154
135
  let proc = this.children[pid] || null;
155
136
  return proc;
156
137
  }
157
138
 
158
- /**
159
- * 获取一个子进程对象
160
- */
139
+ // Get a sub process object
161
140
  getChild() {
162
141
  let proc;
163
142
  const currentPids = Object.keys(this.children);
@@ -180,18 +159,14 @@ class ChildPoolJob extends EventEmitter {
180
159
  return proc;
181
160
  }
182
161
 
183
- /**
184
- * 获取当前pids
185
- */
162
+ // Get current pigs
186
163
  getPids() {
187
164
  let pids = Object.keys(this.children);
188
165
  return pids;
189
166
  }
190
167
 
191
- /**
192
- * kill all
193
- * @param type {String} - 'sequence' | 'parallel'
194
- */
168
+ // kill all
169
+ // type: sequence | parallel
195
170
  killAll(type = 'parallel') {
196
171
  let i = 1;
197
172
  Object.keys(this.children).forEach(key => {
@@ -210,4 +185,6 @@ class ChildPoolJob extends EventEmitter {
210
185
  }
211
186
  }
212
187
 
213
- module.exports = ChildPoolJob;
188
+ module.exports = {
189
+ ChildPoolJob
190
+ };
@@ -0,0 +1,3 @@
1
+ import { ChildJob } from "./child";
2
+ import { ChildPoolJob } from "./child-pool";
3
+ export { ChildJob, ChildPoolJob };
package/jobs/index.js CHANGED
@@ -1,9 +1,7 @@
1
- const ChildJob = require('./child');
2
- const RendererJob = require('./renderer');
3
- const ChildPoolJob = require('./child-pool');
1
+ const { ChildJob } = require('./child');
2
+ const { ChildPoolJob } = require('./child-pool');
4
3
 
5
4
  module.exports = {
6
5
  ChildJob,
7
- RendererJob,
8
6
  ChildPoolJob
9
7
  };
@@ -0,0 +1,4 @@
1
+ declare const _exports: {
2
+ [x: string]: (tasks: any, weightIndex: any, weightTotal: any, context: any) => any;
3
+ };
4
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any, conMap?: {}): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any, currentIndex: any, context: any): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any, id: any): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any, weightTotal: any, context: any): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any, weightTotal: any, connectionsMap: any, context: any): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any, weightIndex: any, weightTotal: any, context: any): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(tasks: any, weightTotal: any): any;
2
+ export = _exports;
@@ -0,0 +1,8 @@
1
+ export declare let polling: string;
2
+ export declare let weights: string;
3
+ export declare let random: string;
4
+ export declare let specify: string;
5
+ export declare let weightsPolling: string;
6
+ export declare let weightsRandom: string;
7
+ export declare let minimumConnection: string;
8
+ export declare let weightsMinimumConnection: string;
@@ -0,0 +1,96 @@
1
+ export = LoadBalancer;
2
+ /**
3
+ * 负载均衡器
4
+ * @intro 参考electron-re项目,并做了一些改动
5
+ * @since 1.0.0
6
+ */
7
+ declare class LoadBalancer {
8
+ static Algorithm: {
9
+ polling: string;
10
+ weights: string;
11
+ random: string;
12
+ specify: string;
13
+ weightsPolling: string;
14
+ weightsRandom: string;
15
+ minimumConnection: string;
16
+ weightsMinimumConnection: string;
17
+ };
18
+ /**
19
+ * @param {Object} options
20
+ * @param {Array } options.targets [ targets for load balancing calculation: [{id: 1, weight: 1}, {id: 2, weight: 2}] ]
21
+ * @param {String} options.algorithm
22
+ */
23
+ constructor(options: {
24
+ targets: any[];
25
+ algorithm: string;
26
+ });
27
+ targets: any[];
28
+ algorithm: string;
29
+ params: {
30
+ currentIndex: number;
31
+ weightIndex: number;
32
+ weightTotal: number;
33
+ connectionsMap: {};
34
+ cpuOccupancyMap: {};
35
+ memoryOccupancyMap: {};
36
+ };
37
+ scheduler: Scheduler;
38
+ memoParams: {
39
+ [x: string]: (id: any) => any[];
40
+ };
41
+ /**
42
+ * 算法参数
43
+ */
44
+ memorizedParams(): {
45
+ [x: string]: (id: any) => any[];
46
+ };
47
+ /**
48
+ * 刷新参数
49
+ */
50
+ refreshParams(pidMap: any): void;
51
+ /**
52
+ * 选举出一个进程
53
+ */
54
+ pickOne(...params: any[]): any;
55
+ /**
56
+ * 选举出多个进程
57
+ */
58
+ pickMulti(count?: number, ...params: any[]): any[];
59
+ /**
60
+ * 计算权重
61
+ */
62
+ calculateWeightIndex(): void;
63
+ /**
64
+ * 计算索引
65
+ */
66
+ calculateIndex(): void;
67
+ /**
68
+ * 清除data
69
+ */
70
+ clean(id: any): void;
71
+ /**
72
+ * 添加一个进程信息
73
+ */
74
+ add(task: any): void;
75
+ /**
76
+ * 删除一个进程信息
77
+ */
78
+ del(target: any): void;
79
+ /**
80
+ * 擦除
81
+ */
82
+ wipe(): void;
83
+ /**
84
+ * 更新计算参数
85
+ */
86
+ updateParams(object: any): void;
87
+ /**
88
+ * 设置targets
89
+ */
90
+ setTargets(targets: any): void;
91
+ /**
92
+ * 设置算法
93
+ */
94
+ setAlgorithm: (algorithm: any) => void;
95
+ }
96
+ import Scheduler = require("./scheduler");
@@ -0,0 +1,16 @@
1
+ export = Scheduler;
2
+ /**
3
+ * 算法调度器
4
+ */
5
+ declare class Scheduler {
6
+ constructor(algorithm: any);
7
+ algorithm: any;
8
+ /**
9
+ * 计算
10
+ */
11
+ calculate(tasks: any, params: any): any;
12
+ /**
13
+ * 设置算法
14
+ */
15
+ setAlgorithm: (algorithm: any) => void;
16
+ }
@@ -0,0 +1,9 @@
1
+ // 加载单个文件(如果是函数,将被执行)
2
+ export declare function loadFile(filepath: string, ...inject: any[]): any;
3
+ // 加载并运行文件
4
+ export declare function execFile(filepath: string, ...inject: any[]): Any;
5
+ export declare function requireFile(filepath: string): any;
6
+ // 模块的绝对路径
7
+ export declare function resolveModule(filepath: string): string;
8
+ // 获取electron目录下文件的绝对路径
9
+ export function getFullpath(filepath: string): string;