@eggjs/cluster 4.0.0-beta.34 → 4.0.0-beta.36
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/dist/agent_worker.d.ts +1 -1
- package/dist/agent_worker.js +50 -65
- package/dist/app_worker.d.ts +1 -1
- package/dist/app_worker.js +127 -165
- package/dist/error/ClusterAgentWorkerError.d.ts +12 -9
- package/dist/error/ClusterAgentWorkerError.js +22 -19
- package/dist/error/ClusterWorkerExceptionError.d.ts +9 -6
- package/dist/error/ClusterWorkerExceptionError.js +17 -14
- package/dist/index.d.ts +20 -15
- package/dist/index.js +20 -16
- package/dist/master.d.ts +89 -86
- package/dist/master.js +425 -556
- package/dist/utils/messenger.d.ts +93 -89
- package/dist/utils/messenger.js +143 -178
- package/dist/utils/mode/base/agent.d.ts +42 -35
- package/dist/utils/mode/base/agent.js +63 -65
- package/dist/utils/mode/base/app.d.ts +53 -45
- package/dist/utils/mode/base/app.js +77 -80
- package/dist/utils/mode/impl/process/agent.d.ts +20 -16
- package/dist/utils/mode/impl/process/agent.js +95 -105
- package/dist/utils/mode/impl/process/app.d.ts +23 -19
- package/dist/utils/mode/impl/process/app.js +116 -118
- package/dist/utils/mode/impl/worker_threads/agent.d.ts +20 -16
- package/dist/utils/mode/impl/worker_threads/agent.js +78 -85
- package/dist/utils/mode/impl/worker_threads/app.d.ts +28 -24
- package/dist/utils/mode/impl/worker_threads/app.js +128 -137
- package/dist/utils/options.d.ts +79 -76
- package/dist/utils/options.js +55 -80
- package/dist/utils/terminate.js +50 -70
- package/dist/utils/worker_manager.d.ts +28 -24
- package/dist/utils/worker_manager.js +68 -74
- package/package.json +33 -34
- package/dist/error/index.d.ts +0 -2
- package/dist/error/index.js +0 -3
- package/dist/utils/terminate.d.ts +0 -6
package/dist/index.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
import { ClusterWorkerExceptionError } from "./error/ClusterWorkerExceptionError.js";
|
|
2
|
+
import { ClusterAgentWorkerError } from "./error/ClusterAgentWorkerError.js";
|
|
3
|
+
import "./utils/options.js";
|
|
1
4
|
import { Master } from "./master.js";
|
|
2
|
-
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
3
7
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
* cluster start flow:
|
|
9
|
+
*
|
|
10
|
+
* [startCluster] -> master -> agent_worker -> new [Agent] -> agentWorkerLoader
|
|
11
|
+
* `-> app_worker -> new [Application] -> appWorkerLoader
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
10
14
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
* start egg app
|
|
16
|
+
* @function Egg#startCluster
|
|
17
|
+
* @param {Object} options {@link Master}
|
|
18
|
+
*/
|
|
19
|
+
async function startCluster(options) {
|
|
20
|
+
await new Master(options).ready();
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ClusterAgentWorkerError, ClusterWorkerExceptionError, Master, startCluster };
|
package/dist/master.d.ts
CHANGED
|
@@ -1,90 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { WorkerManager } from "./utils/worker_manager.js";
|
|
2
|
+
import { Messenger } from "./utils/messenger.js";
|
|
3
|
+
import { AgentProcessUtils } from "./utils/mode/impl/process/agent.js";
|
|
4
|
+
import { AppProcessUtils, AppProcessWorker } from "./utils/mode/impl/process/app.js";
|
|
5
|
+
import { AgentThreadUtils } from "./utils/mode/impl/worker_threads/agent.js";
|
|
6
|
+
import { AppThreadUtils, AppThreadWorker } from "./utils/mode/impl/worker_threads/app.js";
|
|
7
|
+
import { ClusterOptions, ParsedClusterOptions } from "./utils/options.js";
|
|
8
|
+
import { EggConsoleLogger } from "egg-logger";
|
|
9
|
+
import { ReadyEventEmitter } from "get-ready";
|
|
10
|
+
|
|
11
|
+
//#region src/master.d.ts
|
|
12
|
+
interface MasterOptions extends ParsedClusterOptions {
|
|
13
|
+
clusterPort?: number;
|
|
14
|
+
stickyWorkerPort?: number;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
16
|
+
declare class Master extends ReadyEventEmitter {
|
|
17
|
+
#private;
|
|
18
|
+
options: MasterOptions;
|
|
19
|
+
isStarted: boolean;
|
|
20
|
+
workerManager: WorkerManager;
|
|
21
|
+
messenger: Messenger;
|
|
22
|
+
isProduction: boolean;
|
|
23
|
+
agentWorkerIndex: number;
|
|
24
|
+
closed: boolean;
|
|
25
|
+
logger: EggConsoleLogger;
|
|
26
|
+
agentWorker: AgentProcessUtils | AgentThreadUtils;
|
|
27
|
+
appWorker: AppProcessUtils | AppThreadUtils;
|
|
28
|
+
constructor(options?: ClusterOptions);
|
|
29
|
+
startByProcess(): void;
|
|
30
|
+
startByWorkerThreads(): void;
|
|
31
|
+
detectPorts(): Promise<void>;
|
|
32
|
+
log(msg: string, ...args: any[]): void;
|
|
33
|
+
startMasterSocketServer(cb: (err?: Error) => void): void;
|
|
34
|
+
stickyWorker(ip: string): AppProcessWorker | AppThreadWorker;
|
|
35
|
+
forkAgentWorker(): void;
|
|
36
|
+
forkAppWorkers(): void;
|
|
37
|
+
/**
|
|
38
|
+
* close agent worker, App Worker will closed by cluster
|
|
39
|
+
*
|
|
40
|
+
* https://www.exratione.com/2013/05/die-child-process-die/
|
|
41
|
+
* make sure Agent Worker exit before master exit
|
|
42
|
+
*
|
|
43
|
+
* @param {number} timeout - kill agent timeout
|
|
44
|
+
* @return {Promise} -
|
|
45
|
+
*/
|
|
46
|
+
killAgentWorker(timeout: number): Promise<void>;
|
|
47
|
+
killAppWorkers(timeout: number): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Agent Worker exit handler
|
|
50
|
+
* Will exit during startup, and refork during running.
|
|
51
|
+
*/
|
|
52
|
+
onAgentExit(data: {
|
|
53
|
+
/** exit code */
|
|
54
|
+
code: number;
|
|
55
|
+
/** received signal */
|
|
56
|
+
signal: string;
|
|
57
|
+
}): void;
|
|
58
|
+
onAgentStart(): void;
|
|
59
|
+
/**
|
|
60
|
+
* App Worker exit handler
|
|
61
|
+
*/
|
|
62
|
+
onAppExit(data: {
|
|
63
|
+
workerId: number;
|
|
64
|
+
code: number;
|
|
65
|
+
signal: string;
|
|
66
|
+
}): void;
|
|
67
|
+
/**
|
|
68
|
+
* after app worker
|
|
69
|
+
*/
|
|
70
|
+
onAppStart(data: {
|
|
71
|
+
workerId: number;
|
|
72
|
+
address: ListeningAddress;
|
|
73
|
+
}): void;
|
|
74
|
+
/**
|
|
75
|
+
* master exit handler
|
|
76
|
+
*/
|
|
77
|
+
onExit(code: number): void;
|
|
78
|
+
onSignal(signal: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* reload workers, for develop purpose
|
|
81
|
+
*/
|
|
82
|
+
onReload(): void;
|
|
83
|
+
close(): Promise<void>;
|
|
84
|
+
_doClose(): Promise<void>;
|
|
83
85
|
}
|
|
84
86
|
interface ListeningAddress {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
port: number;
|
|
88
|
+
protocol: string;
|
|
89
|
+
address?: string;
|
|
90
|
+
addressType?: number;
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
export { Master, MasterOptions };
|