@midwayjs/bootstrap 3.8.1-beta.1 → 3.9.1
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/LICENSE +21 -0
- package/dist/{bootstrap/bootstrap.d.ts → bootstrap.d.ts} +3 -3
- package/dist/{bootstrap/bootstrap.js → bootstrap.js} +34 -17
- package/dist/index.d.ts +5 -2
- package/dist/index.js +10 -6
- package/dist/interface.d.ts +21 -3
- package/dist/{fork → manager}/base.d.ts +21 -4
- package/dist/{fork → manager}/base.js +62 -8
- package/dist/{fork → manager}/cp.d.ts +2 -1
- package/dist/{fork → manager}/cp.js +13 -8
- package/dist/manager/thread.d.ts +18 -0
- package/dist/{fork → manager}/thread.js +14 -22
- package/dist/sticky.d.ts +3 -0
- package/dist/sticky.js +143 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +23 -3
- package/package.json +6 -8
- package/dist/bootstrap/cluster.d.ts +0 -18
- package/dist/bootstrap/cluster.js +0 -43
- package/dist/fork/thread.d.ts +0 -17
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 - Now midwayjs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IMidwayBootstrapOptions, IMidwayContainer } from '@midwayjs/core';
|
|
2
2
|
import { IMidwayLogger } from '@midwayjs/logger';
|
|
3
|
-
export declare function isTypeScriptEnvironment(): boolean;
|
|
4
3
|
export declare class BootstrapStarter {
|
|
5
4
|
protected appDir: string;
|
|
6
5
|
protected baseDir: string;
|
|
7
6
|
protected globalOptions: Partial<IMidwayBootstrapOptions>;
|
|
8
7
|
protected globalConfig: any;
|
|
9
8
|
private applicationContext;
|
|
10
|
-
|
|
9
|
+
private eventBus;
|
|
10
|
+
configure(options?: IMidwayBootstrapOptions): this;
|
|
11
11
|
init(): Promise<IMidwayContainer>;
|
|
12
12
|
run(): Promise<void>;
|
|
13
13
|
stop(): Promise<void>;
|
|
@@ -24,7 +24,7 @@ export declare class Bootstrap {
|
|
|
24
24
|
*/
|
|
25
25
|
static configure(configuration?: IMidwayBootstrapOptions): typeof Bootstrap;
|
|
26
26
|
static getStarter(): BootstrapStarter;
|
|
27
|
-
static run(): Promise<
|
|
27
|
+
static run(): Promise<IMidwayContainer>;
|
|
28
28
|
static stop(): Promise<void>;
|
|
29
29
|
static reset(): void;
|
|
30
30
|
/**
|
|
@@ -1,45 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Bootstrap = exports.BootstrapStarter =
|
|
3
|
+
exports.Bootstrap = exports.BootstrapStarter = void 0;
|
|
4
4
|
const core_1 = require("@midwayjs/core");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const logger_1 = require("@midwayjs/logger");
|
|
7
7
|
const async_hooks_context_manager_1 = require("@midwayjs/async-hooks-context-manager");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
// eslint-disable-next-line node/no-deprecated-api
|
|
14
|
-
return TS_MODE_PROCESS_FLAG === 'true' || !!require.extensions['.ts'];
|
|
15
|
-
}
|
|
16
|
-
exports.isTypeScriptEnvironment = isTypeScriptEnvironment;
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
const event_bus_1 = require("@midwayjs/event-bus");
|
|
10
|
+
const sticky_1 = require("./sticky");
|
|
17
11
|
class BootstrapStarter {
|
|
18
12
|
constructor() {
|
|
19
13
|
this.globalOptions = {};
|
|
20
14
|
}
|
|
21
|
-
configure(options) {
|
|
15
|
+
configure(options = {}) {
|
|
22
16
|
this.globalOptions = options;
|
|
23
17
|
return this;
|
|
24
18
|
}
|
|
25
19
|
async init() {
|
|
26
|
-
this.appDir = this.globalOptions.appDir
|
|
27
|
-
|
|
20
|
+
this.appDir = this.globalOptions.appDir =
|
|
21
|
+
this.globalOptions.appDir || process.cwd();
|
|
22
|
+
this.baseDir = this.globalOptions.baseDir = this.getBaseDir();
|
|
23
|
+
if (process.env['MIDWAY_FORK_MODE']) {
|
|
24
|
+
if (process.env['MIDWAY_FORK_MODE'] === 'cluster') {
|
|
25
|
+
this.eventBus = new event_bus_1.ChildProcessEventBus({
|
|
26
|
+
isWorker: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (process.env['MIDWAY_FORK_MODE'] === 'thread') {
|
|
30
|
+
this.eventBus = new event_bus_1.ThreadEventBus({
|
|
31
|
+
isWorker: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
28
35
|
this.applicationContext = await (0, core_1.initializeGlobalApplicationContext)({
|
|
29
|
-
...this.globalOptions,
|
|
30
|
-
appDir: this.appDir,
|
|
31
|
-
baseDir: this.baseDir,
|
|
32
36
|
asyncContextManager: (0, async_hooks_context_manager_1.createContextManager)(),
|
|
37
|
+
...this.globalOptions,
|
|
33
38
|
});
|
|
34
39
|
return this.applicationContext;
|
|
35
40
|
}
|
|
36
41
|
async run() {
|
|
37
42
|
this.applicationContext = await this.init();
|
|
43
|
+
if (this.eventBus) {
|
|
44
|
+
await this.eventBus.start();
|
|
45
|
+
if (process.env['MIDWAY_STICKY_MODE'] === 'true') {
|
|
46
|
+
const applicationManager = this.applicationContext.get(core_1.MidwayApplicationManager);
|
|
47
|
+
const io = applicationManager.getApplication('socketIO');
|
|
48
|
+
(0, sticky_1.setupWorker)(io);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
38
51
|
}
|
|
39
52
|
async stop() {
|
|
40
53
|
if (this.applicationContext) {
|
|
41
54
|
await (0, core_1.destroyGlobalApplicationContext)(this.applicationContext);
|
|
42
55
|
}
|
|
56
|
+
if (this.eventBus) {
|
|
57
|
+
await this.eventBus.stop();
|
|
58
|
+
}
|
|
43
59
|
}
|
|
44
60
|
getApplicationContext() {
|
|
45
61
|
return this.applicationContext;
|
|
@@ -48,7 +64,7 @@ class BootstrapStarter {
|
|
|
48
64
|
if (this.globalOptions.baseDir) {
|
|
49
65
|
return this.globalOptions.baseDir;
|
|
50
66
|
}
|
|
51
|
-
if (isTypeScriptEnvironment()) {
|
|
67
|
+
if ((0, util_1.isTypeScriptEnvironment)()) {
|
|
52
68
|
return (0, path_1.join)(this.appDir, 'src');
|
|
53
69
|
}
|
|
54
70
|
else {
|
|
@@ -113,6 +129,7 @@ class Bootstrap {
|
|
|
113
129
|
.then(() => {
|
|
114
130
|
this.logger.info('[midway:bootstrap] current app started');
|
|
115
131
|
global['MIDWAY_BOOTSTRAP_APP_READY'] = true;
|
|
132
|
+
return this.getApplicationContext();
|
|
116
133
|
})
|
|
117
134
|
.catch(err => {
|
|
118
135
|
this.logger.error(err);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './interface';
|
|
2
|
-
export { isTypeScriptEnvironment
|
|
3
|
-
export {
|
|
2
|
+
export { isTypeScriptEnvironment } from './util';
|
|
3
|
+
export { Bootstrap, BootstrapStarter } from './bootstrap';
|
|
4
|
+
export { ClusterManager } from './manager/cp';
|
|
5
|
+
export { AbstractForkManager } from './manager/base';
|
|
6
|
+
export { setupStickyMaster } from './sticky';
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -14,13 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.setupStickyMaster = exports.AbstractForkManager = exports.ClusterManager = exports.BootstrapStarter = exports.Bootstrap = exports.isTypeScriptEnvironment = void 0;
|
|
18
18
|
__exportStar(require("./interface"), exports);
|
|
19
|
-
var
|
|
20
|
-
Object.defineProperty(exports, "isTypeScriptEnvironment", { enumerable: true, get: function () { return
|
|
19
|
+
var util_1 = require("./util");
|
|
20
|
+
Object.defineProperty(exports, "isTypeScriptEnvironment", { enumerable: true, get: function () { return util_1.isTypeScriptEnvironment; } });
|
|
21
|
+
var bootstrap_1 = require("./bootstrap");
|
|
21
22
|
Object.defineProperty(exports, "Bootstrap", { enumerable: true, get: function () { return bootstrap_1.Bootstrap; } });
|
|
22
23
|
Object.defineProperty(exports, "BootstrapStarter", { enumerable: true, get: function () { return bootstrap_1.BootstrapStarter; } });
|
|
23
|
-
var
|
|
24
|
-
Object.defineProperty(exports, "
|
|
25
|
-
|
|
24
|
+
var cp_1 = require("./manager/cp");
|
|
25
|
+
Object.defineProperty(exports, "ClusterManager", { enumerable: true, get: function () { return cp_1.ClusterManager; } });
|
|
26
|
+
var base_1 = require("./manager/base");
|
|
27
|
+
Object.defineProperty(exports, "AbstractForkManager", { enumerable: true, get: function () { return base_1.AbstractForkManager; } });
|
|
28
|
+
var sticky_1 = require("./sticky");
|
|
29
|
+
Object.defineProperty(exports, "setupStickyMaster", { enumerable: true, get: function () { return sticky_1.setupStickyMaster; } });
|
|
26
30
|
//# sourceMappingURL=index.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import type { IMidwayBootstrapOptions } from '@midwayjs/core';
|
|
5
4
|
import type { IMidwayLogger } from '@midwayjs/logger';
|
|
6
5
|
import { ClusterSettings } from 'cluster';
|
|
7
6
|
import { WorkerOptions } from 'worker_threads';
|
|
@@ -21,8 +20,27 @@ export interface ForkOptions {
|
|
|
21
20
|
limit?: number;
|
|
22
21
|
duration?: number;
|
|
23
22
|
logger?: IMidwayLogger | Console;
|
|
23
|
+
/**
|
|
24
|
+
* Some environments set to worker
|
|
25
|
+
*/
|
|
26
|
+
env?: Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Worker init Timeout, default is 30s,
|
|
29
|
+
*/
|
|
30
|
+
workerInitTimeout?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface IForkManager<T> {
|
|
33
|
+
start(): any;
|
|
34
|
+
close(): any;
|
|
35
|
+
hasWorker(workerId: string): boolean;
|
|
36
|
+
getWorker(workerId: string): T;
|
|
37
|
+
getWorkerIds(): string[];
|
|
38
|
+
isWorkerDead(worker: T): boolean;
|
|
39
|
+
isPrimary(): boolean;
|
|
24
40
|
}
|
|
25
|
-
export declare type ClusterOptions = ForkOptions & ClusterSettings
|
|
41
|
+
export declare type ClusterOptions = ForkOptions & ClusterSettings & {
|
|
42
|
+
sticky?: boolean;
|
|
43
|
+
stickyLoadBalancingMethod?: 'random' | 'round-robin' | 'least-connection';
|
|
44
|
+
};
|
|
26
45
|
export declare type ThreadOptions = ForkOptions & WorkerOptions;
|
|
27
|
-
export declare type ClusterBootstrapOptions = IMidwayBootstrapOptions & ClusterOptions;
|
|
28
46
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ForkOptions } from '../interface';
|
|
2
|
-
import type { IEventBus } from '@midwayjs/event-bus';
|
|
2
|
+
import type { IEventBus, EventBusOptions } from '@midwayjs/event-bus';
|
|
3
3
|
export declare abstract class AbstractForkManager<T, ClusterOptions extends ForkOptions> {
|
|
4
4
|
readonly options: ClusterOptions;
|
|
5
5
|
private reforks;
|
|
@@ -7,9 +7,10 @@ export declare abstract class AbstractForkManager<T, ClusterOptions extends Fork
|
|
|
7
7
|
private unexpectedCount;
|
|
8
8
|
private disconnects;
|
|
9
9
|
private hub;
|
|
10
|
-
protected workers:
|
|
10
|
+
protected workers: Map<string, T>;
|
|
11
11
|
protected eventBus: IEventBus<T>;
|
|
12
12
|
private isClosing;
|
|
13
|
+
private exitListener;
|
|
13
14
|
protected constructor(options: ClusterOptions);
|
|
14
15
|
start(): Promise<void>;
|
|
15
16
|
protected tryToRefork(oldWorker: T): void;
|
|
@@ -30,13 +31,29 @@ export declare abstract class AbstractForkManager<T, ClusterOptions extends Fork
|
|
|
30
31
|
*/
|
|
31
32
|
protected onReachReforkLimit(): void;
|
|
32
33
|
protected killWorker(worker: any, timeout: any): Promise<void>;
|
|
33
|
-
|
|
34
|
+
stop(timeout?: number): Promise<void>;
|
|
35
|
+
hasWorker(workerId: string): boolean;
|
|
36
|
+
getWorker(workerId: string): T;
|
|
37
|
+
getWorkerIds(): string[];
|
|
38
|
+
onStop(exitListener: any): void;
|
|
39
|
+
protected bindClose(): void;
|
|
40
|
+
/**
|
|
41
|
+
* on bootstrap receive a exit signal
|
|
42
|
+
* @param signal
|
|
43
|
+
*/
|
|
44
|
+
private onSignal;
|
|
45
|
+
/**
|
|
46
|
+
* on bootstrap process exit
|
|
47
|
+
* @param code
|
|
48
|
+
*/
|
|
49
|
+
private onMasterExit;
|
|
34
50
|
abstract createWorker(oldWorker?: T): T;
|
|
35
51
|
abstract bindWorkerDisconnect(listener: (worker: T) => void): void;
|
|
36
52
|
abstract bindWorkerExit(listener: (worker: T, code: any, signal: any) => void): void;
|
|
37
53
|
abstract getWorkerId(worker: T): string;
|
|
38
54
|
abstract isWorkerDead(worker: T): boolean;
|
|
39
55
|
abstract closeWorker(worker: T): any;
|
|
40
|
-
abstract createEventBus(): IEventBus<T>;
|
|
56
|
+
abstract createEventBus(eventBusOptions: EventBusOptions): IEventBus<T>;
|
|
57
|
+
abstract isPrimary(): boolean;
|
|
41
58
|
}
|
|
42
59
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -15,16 +15,20 @@ class AbstractForkManager {
|
|
|
15
15
|
this.unexpectedCount = 0;
|
|
16
16
|
this.disconnects = {};
|
|
17
17
|
this.hub = new events_1.EventEmitter();
|
|
18
|
-
this.workers = new
|
|
18
|
+
this.workers = new Map();
|
|
19
19
|
this.isClosing = false;
|
|
20
20
|
options.count = options.count || os.cpus().length - 1;
|
|
21
21
|
options.refork = options.refork !== false;
|
|
22
22
|
options.limit = options.limit || 60;
|
|
23
23
|
options.duration = options.duration || 60000; // 1 min
|
|
24
24
|
options.logger = options.logger || console;
|
|
25
|
-
|
|
25
|
+
options.workerInitTimeout = options.workerInitTimeout || 30000;
|
|
26
|
+
this.eventBus = this.createEventBus({
|
|
27
|
+
initTimeout: options.workerInitTimeout,
|
|
28
|
+
});
|
|
26
29
|
}
|
|
27
30
|
async start() {
|
|
31
|
+
debug('Start manager with options: %j', this.options);
|
|
28
32
|
this.bindWorkerDisconnect(worker => {
|
|
29
33
|
debug(' - worker(%s): trigger event = disconnect', this.getWorkerId(worker));
|
|
30
34
|
const log = this.options.logger[worker['disableRefork'] ? 'info' : 'error'];
|
|
@@ -48,7 +52,7 @@ class AbstractForkManager {
|
|
|
48
52
|
this.bindWorkerExit((worker, code, signal) => {
|
|
49
53
|
debug(' - worker(%s): trigger event = exit', this.getWorkerId(worker));
|
|
50
54
|
// remove worker
|
|
51
|
-
|
|
55
|
+
this.workers.delete(this.getWorkerId(worker));
|
|
52
56
|
if (worker['disableRefork']) {
|
|
53
57
|
return;
|
|
54
58
|
}
|
|
@@ -68,6 +72,7 @@ class AbstractForkManager {
|
|
|
68
72
|
this.tryToRefork(worker);
|
|
69
73
|
this.onUnexpected(worker, code, signal);
|
|
70
74
|
});
|
|
75
|
+
this.bindClose();
|
|
71
76
|
this.hub.on('reachReforkLimit', this.onReachReforkLimit.bind(this));
|
|
72
77
|
// defer to set the listeners
|
|
73
78
|
// so you can listen this by your own
|
|
@@ -79,7 +84,8 @@ class AbstractForkManager {
|
|
|
79
84
|
for (let i = 0; i < this.options.count; i++) {
|
|
80
85
|
const w = this.createWorker();
|
|
81
86
|
debug(' - worker(%s) created', this.getWorkerId(w));
|
|
82
|
-
this.
|
|
87
|
+
this.eventBus.addWorker(w);
|
|
88
|
+
this.workers.set(this.getWorkerId(w), w);
|
|
83
89
|
}
|
|
84
90
|
await this.eventBus.start();
|
|
85
91
|
}
|
|
@@ -87,8 +93,7 @@ class AbstractForkManager {
|
|
|
87
93
|
if (this.allowRefork()) {
|
|
88
94
|
debug(' - worker(%s): allow refork and will fork new', this.getWorkerId(oldWorker));
|
|
89
95
|
const newWorker = this.createWorker(oldWorker);
|
|
90
|
-
this.workers.
|
|
91
|
-
debug('----after create', newWorker.process.pid);
|
|
96
|
+
this.workers.set(this.getWorkerId(newWorker), newWorker);
|
|
92
97
|
this.options.logger.info('[%s] [bootstrap:master:%s] new worker:%s fork (state: %s)', (0, util_1.logDate)(), process.pid, this.getWorkerId(newWorker), newWorker['state']);
|
|
93
98
|
this.eventBus.addWorker(newWorker);
|
|
94
99
|
}
|
|
@@ -155,14 +160,63 @@ class AbstractForkManager {
|
|
|
155
160
|
// subProcess.kill is wrapped to subProcess.destroy, it will wait to disconnected.
|
|
156
161
|
(worker.process || worker).kill('SIGKILL');
|
|
157
162
|
}
|
|
158
|
-
async
|
|
163
|
+
async stop(timeout = 2000) {
|
|
159
164
|
debug('run close');
|
|
160
165
|
this.isClosing = true;
|
|
161
166
|
await this.eventBus.stop();
|
|
162
|
-
for (const worker of this.workers) {
|
|
167
|
+
for (const worker of this.workers.values()) {
|
|
163
168
|
worker['disableRefork'] = true;
|
|
164
169
|
await this.killWorker(worker, timeout);
|
|
165
170
|
}
|
|
171
|
+
if (this.exitListener) {
|
|
172
|
+
await this.exitListener();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
hasWorker(workerId) {
|
|
176
|
+
return this.workers.has(workerId);
|
|
177
|
+
}
|
|
178
|
+
getWorker(workerId) {
|
|
179
|
+
return this.workers.get(workerId);
|
|
180
|
+
}
|
|
181
|
+
getWorkerIds() {
|
|
182
|
+
return Array.from(this.workers.keys());
|
|
183
|
+
}
|
|
184
|
+
onStop(exitListener) {
|
|
185
|
+
this.exitListener = exitListener;
|
|
186
|
+
}
|
|
187
|
+
bindClose() {
|
|
188
|
+
// kill(2) Ctrl-C
|
|
189
|
+
process.once('SIGINT', this.onSignal.bind(this, 'SIGINT'));
|
|
190
|
+
// kill(3) Ctrl-\
|
|
191
|
+
process.once('SIGQUIT', this.onSignal.bind(this, 'SIGQUIT'));
|
|
192
|
+
// kill(15) default
|
|
193
|
+
process.once('SIGTERM', this.onSignal.bind(this, 'SIGTERM'));
|
|
194
|
+
process.once('exit', this.onMasterExit.bind(this));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* on bootstrap receive a exit signal
|
|
198
|
+
* @param signal
|
|
199
|
+
*/
|
|
200
|
+
async onSignal(signal) {
|
|
201
|
+
if (!this.isClosing) {
|
|
202
|
+
this.options.logger.info('[bootstrap:master] receive signal %s, closing', signal);
|
|
203
|
+
try {
|
|
204
|
+
await this.stop();
|
|
205
|
+
this.options.logger.info('[bootstrap:master] close done, exiting with code:0');
|
|
206
|
+
process.exit(0);
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
this.options.logger.error('[midway:master] close with error: ', err);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* on bootstrap process exit
|
|
216
|
+
* @param code
|
|
217
|
+
*/
|
|
218
|
+
onMasterExit(code) {
|
|
219
|
+
this.options.logger.info('[bootstrap:master] exit with code:%s', code);
|
|
166
220
|
}
|
|
167
221
|
}
|
|
168
222
|
exports.AbstractForkManager = AbstractForkManager;
|
|
@@ -11,6 +11,7 @@ export declare class ClusterManager extends AbstractForkManager<Worker, ClusterO
|
|
|
11
11
|
getWorkerId(worker: Worker): string;
|
|
12
12
|
isWorkerDead(worker: Worker): boolean;
|
|
13
13
|
closeWorker(worker: Worker): void;
|
|
14
|
-
createEventBus(): any;
|
|
14
|
+
createEventBus(options: any): any;
|
|
15
|
+
isPrimary(): boolean;
|
|
15
16
|
}
|
|
16
17
|
//# sourceMappingURL=cp.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClusterManager = void 0;
|
|
4
|
-
const
|
|
4
|
+
const event_bus_1 = require("@midwayjs/event-bus");
|
|
5
5
|
const base_1 = require("./base");
|
|
6
|
-
const path_1 = require("path");
|
|
7
6
|
const cluster = require('cluster');
|
|
8
7
|
const util_1 = require("util");
|
|
8
|
+
const util_2 = require("../util");
|
|
9
9
|
const debug = (0, util_1.debuglog)('midway:bootstrap');
|
|
10
10
|
class ClusterManager extends base_1.AbstractForkManager {
|
|
11
11
|
constructor(options = {}) {
|
|
@@ -13,10 +13,9 @@ class ClusterManager extends base_1.AbstractForkManager {
|
|
|
13
13
|
this.options = options;
|
|
14
14
|
options.args = options.args || [];
|
|
15
15
|
options.execArgv = options.execArgv || [];
|
|
16
|
-
if ((0,
|
|
16
|
+
if ((0, util_2.isTypeScriptEnvironment)()) {
|
|
17
17
|
options.execArgv.push(...['--require', 'ts-node/register']);
|
|
18
18
|
}
|
|
19
|
-
debug('Init cluster manager with options: %j', options);
|
|
20
19
|
}
|
|
21
20
|
createWorker() {
|
|
22
21
|
if (cluster['setupPrimary']) {
|
|
@@ -25,8 +24,11 @@ class ClusterManager extends base_1.AbstractForkManager {
|
|
|
25
24
|
else if (cluster['setupMaster']) {
|
|
26
25
|
cluster['setupMaster'](this.options);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
return cluster.fork({
|
|
28
|
+
MIDWAY_FORK_MODE: 'cluster',
|
|
29
|
+
MIDWAY_STICKY_MODE: this.options.sticky ? 'true' : 'false',
|
|
30
|
+
...this.options.env,
|
|
31
|
+
});
|
|
30
32
|
}
|
|
31
33
|
bindWorkerDisconnect(listener) {
|
|
32
34
|
debug('Bind cluster.disconnect event');
|
|
@@ -45,8 +47,11 @@ class ClusterManager extends base_1.AbstractForkManager {
|
|
|
45
47
|
closeWorker(worker) {
|
|
46
48
|
worker.kill('SIGTERM');
|
|
47
49
|
}
|
|
48
|
-
createEventBus() {
|
|
49
|
-
return new
|
|
50
|
+
createEventBus(options) {
|
|
51
|
+
return new event_bus_1.ChildProcessEventBus(options);
|
|
52
|
+
}
|
|
53
|
+
isPrimary() {
|
|
54
|
+
return !cluster.isWorker;
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
exports.ClusterManager = ClusterManager;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ThreadOptions } from '../interface';
|
|
3
|
+
import { AbstractForkManager } from './base';
|
|
4
|
+
import { Worker } from 'worker_threads';
|
|
5
|
+
export declare class ThreadManager extends AbstractForkManager<Worker, ThreadOptions> {
|
|
6
|
+
readonly options: ThreadOptions;
|
|
7
|
+
private workerExitListener;
|
|
8
|
+
constructor(options?: ThreadOptions);
|
|
9
|
+
createWorker(): Worker;
|
|
10
|
+
bindWorkerDisconnect(listener: (worker: Worker) => void): void;
|
|
11
|
+
bindWorkerExit(listener: (worker: Worker, code: any, signal: any) => void): void;
|
|
12
|
+
getWorkerId(worker: Worker): any;
|
|
13
|
+
isWorkerDead(worker: Worker): boolean;
|
|
14
|
+
closeWorker(worker: Worker): Promise<void>;
|
|
15
|
+
createEventBus(options: any): any;
|
|
16
|
+
isPrimary(): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=thread.d.ts.map
|
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ThreadManager = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
4
|
const base_1 = require("./base");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let ThreadEventBus = null;
|
|
10
|
-
try {
|
|
11
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
12
|
-
threads = require('worker_threads');
|
|
13
|
-
shareEnv = threads.SHARE_ENV;
|
|
14
|
-
Worker = threads.Worker;
|
|
15
|
-
ThreadEventBus = require('@midwayjs/event-bus').ThreadEventBus;
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
// ignore not support worker_threads
|
|
19
|
-
}
|
|
5
|
+
const worker_threads_1 = require("worker_threads");
|
|
6
|
+
const event_bus_1 = require("@midwayjs/event-bus");
|
|
7
|
+
const util_1 = require("../util");
|
|
20
8
|
class ThreadManager extends base_1.AbstractForkManager {
|
|
21
9
|
constructor(options = {}) {
|
|
22
10
|
super(options);
|
|
23
11
|
this.options = options;
|
|
24
12
|
options.argv = options.argv || [];
|
|
25
13
|
options.execArgv = options.execArgv || [];
|
|
14
|
+
process.env.MIDWAY_FORK_MODE = 'thread';
|
|
26
15
|
}
|
|
27
16
|
createWorker() {
|
|
28
17
|
let w;
|
|
@@ -30,21 +19,21 @@ class ThreadManager extends base_1.AbstractForkManager {
|
|
|
30
19
|
require(${JSON.stringify(this.options.exec)});
|
|
31
20
|
`;
|
|
32
21
|
// 当前是 ts 环境
|
|
33
|
-
if ((0,
|
|
22
|
+
if ((0, util_1.isTypeScriptEnvironment)()) {
|
|
34
23
|
content = `
|
|
35
24
|
require("ts-node/register/transpile-only");
|
|
36
25
|
${content}
|
|
37
26
|
`;
|
|
38
|
-
w = new Worker(content, { eval: true, env:
|
|
27
|
+
w = new worker_threads_1.Worker(content, { eval: true, env: worker_threads_1.SHARE_ENV });
|
|
39
28
|
w['_originThreadId'] = String(w.threadId);
|
|
40
29
|
this.options.logger.info('new worker thread with ts-node, threadId = %s.', this.getWorkerId(w));
|
|
41
30
|
}
|
|
42
31
|
else {
|
|
43
|
-
w = new Worker(content, { eval: true, env:
|
|
32
|
+
w = new worker_threads_1.Worker(content, { eval: true, env: worker_threads_1.SHARE_ENV });
|
|
44
33
|
this.options.logger.info('new worker thread, threadId = %s.', this.getWorkerId(w));
|
|
45
34
|
}
|
|
46
35
|
w.on('exit', code => {
|
|
47
|
-
this.
|
|
36
|
+
this.workerExitListener(w, code);
|
|
48
37
|
});
|
|
49
38
|
return w;
|
|
50
39
|
}
|
|
@@ -52,7 +41,7 @@ class ThreadManager extends base_1.AbstractForkManager {
|
|
|
52
41
|
// this.disconnectListener = listener;
|
|
53
42
|
}
|
|
54
43
|
bindWorkerExit(listener) {
|
|
55
|
-
this.
|
|
44
|
+
this.workerExitListener = listener;
|
|
56
45
|
}
|
|
57
46
|
getWorkerId(worker) {
|
|
58
47
|
return worker['_originThreadId'] || String(worker.threadId);
|
|
@@ -63,8 +52,11 @@ class ThreadManager extends base_1.AbstractForkManager {
|
|
|
63
52
|
async closeWorker(worker) {
|
|
64
53
|
await worker.terminate();
|
|
65
54
|
}
|
|
66
|
-
createEventBus() {
|
|
67
|
-
return new ThreadEventBus();
|
|
55
|
+
createEventBus(options) {
|
|
56
|
+
return new event_bus_1.ThreadEventBus(options);
|
|
57
|
+
}
|
|
58
|
+
isPrimary() {
|
|
59
|
+
return worker_threads_1.isMainThread;
|
|
68
60
|
}
|
|
69
61
|
}
|
|
70
62
|
exports.ThreadManager = ThreadManager;
|
package/dist/sticky.d.ts
ADDED
package/dist/sticky.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupWorker = exports.setupStickyMaster = void 0;
|
|
4
|
+
const cluster = require('cluster');
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const randomId = () => (0, crypto_1.randomBytes)(8).toString('hex');
|
|
7
|
+
function setupStickyMaster(httpServer, opts = {}) {
|
|
8
|
+
const options = {
|
|
9
|
+
loadBalancingMethod: 'least-connection',
|
|
10
|
+
...opts,
|
|
11
|
+
};
|
|
12
|
+
const sessionIdToWorker = new Map();
|
|
13
|
+
const sidRegex = /sid=([\w-]{20})/;
|
|
14
|
+
let currentIndex = 0; // for round-robin load balancing
|
|
15
|
+
const computeWorkerId = data => {
|
|
16
|
+
const match = sidRegex.exec(data);
|
|
17
|
+
if (match) {
|
|
18
|
+
const sid = match[1];
|
|
19
|
+
const workerId = sessionIdToWorker.get(sid);
|
|
20
|
+
if (workerId && cluster.workers[workerId]) {
|
|
21
|
+
return workerId;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
switch (options.loadBalancingMethod) {
|
|
25
|
+
case 'random': {
|
|
26
|
+
const workerIds = Object.keys(cluster.workers);
|
|
27
|
+
return workerIds[Math.floor(Math.random() * workerIds.length)];
|
|
28
|
+
}
|
|
29
|
+
case 'round-robin': {
|
|
30
|
+
const workerIds = Object.keys(cluster.workers);
|
|
31
|
+
currentIndex++;
|
|
32
|
+
if (currentIndex >= workerIds.length) {
|
|
33
|
+
currentIndex = 0;
|
|
34
|
+
}
|
|
35
|
+
return workerIds[currentIndex];
|
|
36
|
+
}
|
|
37
|
+
case 'least-connection':
|
|
38
|
+
// eslint-disable-next-line no-case-declarations
|
|
39
|
+
let leastActiveWorker;
|
|
40
|
+
for (const id in cluster.workers) {
|
|
41
|
+
const worker = cluster.workers[id];
|
|
42
|
+
if (leastActiveWorker === undefined) {
|
|
43
|
+
leastActiveWorker = worker;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const c1 = worker['clientsCount'] || 0;
|
|
47
|
+
const c2 = leastActiveWorker['clientsCount'] || 0;
|
|
48
|
+
if (c1 < c2) {
|
|
49
|
+
leastActiveWorker = worker;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return leastActiveWorker.id;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
httpServer.on('connection', socket => {
|
|
57
|
+
let workerId, connectionId;
|
|
58
|
+
const sendCallback = err => {
|
|
59
|
+
if (err) {
|
|
60
|
+
socket.destroy();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
socket.on('data', buffer => {
|
|
64
|
+
const data = buffer.toString();
|
|
65
|
+
if (workerId && connectionId) {
|
|
66
|
+
cluster.workers[workerId].send({ type: 'sticky:http-chunk', data, connectionId }, sendCallback);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
workerId = computeWorkerId(data);
|
|
70
|
+
const mayHaveMultipleChunks = !(data.startsWith('GET') ||
|
|
71
|
+
data
|
|
72
|
+
.substring(0, data.indexOf('\r\n\r\n'))
|
|
73
|
+
.includes('pgrade: websocket'));
|
|
74
|
+
socket.pause();
|
|
75
|
+
if (mayHaveMultipleChunks) {
|
|
76
|
+
connectionId = randomId();
|
|
77
|
+
}
|
|
78
|
+
cluster.workers[workerId].send({ type: 'sticky:connection', data, connectionId }, socket, {
|
|
79
|
+
keepOpen: mayHaveMultipleChunks,
|
|
80
|
+
}, sendCallback);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
// this is needed to properly detect the end of the HTTP request body
|
|
84
|
+
httpServer.on('request', req => {
|
|
85
|
+
req.on('data', () => { });
|
|
86
|
+
});
|
|
87
|
+
cluster.on('message', (worker, { type, data }) => {
|
|
88
|
+
switch (type) {
|
|
89
|
+
case 'sticky:connection':
|
|
90
|
+
sessionIdToWorker.set(data, worker.id);
|
|
91
|
+
if (options.loadBalancingMethod === 'least-connection') {
|
|
92
|
+
worker['clientsCount'] = (worker['clientsCount'] || 0) + 1;
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
case 'sticky:disconnection':
|
|
96
|
+
sessionIdToWorker.delete(data);
|
|
97
|
+
if (options.loadBalancingMethod === 'least-connection') {
|
|
98
|
+
worker['clientsCount']--;
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
exports.setupStickyMaster = setupStickyMaster;
|
|
105
|
+
function setupWorker(io) {
|
|
106
|
+
// store connections that may receive multiple chunks
|
|
107
|
+
const sockets = new Map();
|
|
108
|
+
process.on('message', ({ type, data, connectionId }, socket) => {
|
|
109
|
+
switch (type) {
|
|
110
|
+
case 'sticky:connection':
|
|
111
|
+
if (!socket) {
|
|
112
|
+
// might happen if the socket is closed during the transfer to the worker
|
|
113
|
+
// see https://nodejs.org/api/child_process.html#child_process_example_sending_a_socket_object
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
io.httpServer.emit('connection', socket); // inject connection
|
|
117
|
+
socket.emit('data', Buffer.from(data)); // republish first chunk
|
|
118
|
+
socket.resume();
|
|
119
|
+
if (connectionId) {
|
|
120
|
+
sockets.set(connectionId, socket);
|
|
121
|
+
socket.on('close', () => {
|
|
122
|
+
sockets.delete(connectionId);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case 'sticky:http-chunk': {
|
|
127
|
+
const socket = sockets.get(connectionId);
|
|
128
|
+
if (socket) {
|
|
129
|
+
socket.emit('data', Buffer.from(data));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const ignoreError = () => { }; // the next request will fail anyway
|
|
135
|
+
io.engine.on('connection', socket => {
|
|
136
|
+
process.send({ type: 'sticky:connection', data: socket.id }, ignoreError);
|
|
137
|
+
socket.once('close', () => {
|
|
138
|
+
process.send({ type: 'sticky:disconnection', data: socket.id }, ignoreError);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
exports.setupWorker = setupWorker;
|
|
143
|
+
//# sourceMappingURL=sticky.js.map
|
package/dist/util.d.ts
CHANGED
package/dist/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sleep = exports.logDate = void 0;
|
|
3
|
+
exports.isTypeScriptEnvironment = exports.sleep = exports.logDate = void 0;
|
|
4
4
|
function logDate() {
|
|
5
5
|
const d = new Date();
|
|
6
6
|
let date = d.getDate();
|
|
@@ -30,8 +30,19 @@ function logDate() {
|
|
|
30
30
|
else if (milliseconds < 100) {
|
|
31
31
|
milliseconds = '0' + milliseconds;
|
|
32
32
|
}
|
|
33
|
-
return d.getFullYear() +
|
|
34
|
-
|
|
33
|
+
return (d.getFullYear() +
|
|
34
|
+
'-' +
|
|
35
|
+
month +
|
|
36
|
+
'-' +
|
|
37
|
+
date +
|
|
38
|
+
' ' +
|
|
39
|
+
hours +
|
|
40
|
+
':' +
|
|
41
|
+
mintues +
|
|
42
|
+
':' +
|
|
43
|
+
seconds +
|
|
44
|
+
'.' +
|
|
45
|
+
milliseconds);
|
|
35
46
|
}
|
|
36
47
|
exports.logDate = logDate;
|
|
37
48
|
async function sleep(timeout) {
|
|
@@ -40,4 +51,13 @@ async function sleep(timeout) {
|
|
|
40
51
|
});
|
|
41
52
|
}
|
|
42
53
|
exports.sleep = sleep;
|
|
54
|
+
function isTypeScriptEnvironment() {
|
|
55
|
+
const TS_MODE_PROCESS_FLAG = process.env.MIDWAY_TS_MODE;
|
|
56
|
+
if ('false' === TS_MODE_PROCESS_FLAG) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// eslint-disable-next-line node/no-deprecated-api
|
|
60
|
+
return TS_MODE_PROCESS_FLAG === 'true' || !!require.extensions['.ts'];
|
|
61
|
+
}
|
|
62
|
+
exports.isTypeScriptEnvironment = isTypeScriptEnvironment;
|
|
43
63
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/bootstrap",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.1",
|
|
4
4
|
"description": "midwayjs bootstrap",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,14 +21,12 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@midwayjs/async-hooks-context-manager": "^3.
|
|
25
|
-
"@midwayjs/event-bus": "
|
|
24
|
+
"@midwayjs/async-hooks-context-manager": "^3.9.0",
|
|
25
|
+
"@midwayjs/event-bus": "^1.0.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@midwayjs/core": "^3.
|
|
28
|
+
"@midwayjs/core": "^3.9.0",
|
|
29
29
|
"@midwayjs/logger": "^2.15.0",
|
|
30
|
-
"@midwayjs/socketio": "^3.8.0",
|
|
31
|
-
"@midwayjs/web": "^3.8.0",
|
|
32
30
|
"request": "2.88.2",
|
|
33
31
|
"socket.io-client": "4.5.3"
|
|
34
32
|
},
|
|
@@ -38,7 +36,7 @@
|
|
|
38
36
|
"url": "https://github.com/midwayjs/midway.git"
|
|
39
37
|
},
|
|
40
38
|
"engines": {
|
|
41
|
-
"node": ">=12"
|
|
39
|
+
"node": ">=12.11.0"
|
|
42
40
|
},
|
|
43
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "83204ee2b6c0a1e9a1f50b504869b1d48fc18895"
|
|
44
42
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Bootstrap, BootstrapStarter } from './bootstrap';
|
|
2
|
-
import { ClusterBootstrapOptions } from '../interface';
|
|
3
|
-
export declare class ClusterBootstrapStarter extends BootstrapStarter {
|
|
4
|
-
protected globalOptions: ClusterBootstrapOptions;
|
|
5
|
-
private clusterManager;
|
|
6
|
-
init(): Promise<any>;
|
|
7
|
-
run(): Promise<void>;
|
|
8
|
-
stop(): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
export declare class ClusterBootstrap extends Bootstrap {
|
|
11
|
-
/**
|
|
12
|
-
* set global configuration for midway
|
|
13
|
-
* @param configuration
|
|
14
|
-
*/
|
|
15
|
-
static configure(configuration?: ClusterBootstrapOptions): typeof Bootstrap;
|
|
16
|
-
static getStarter(): BootstrapStarter;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=cluster.d.ts.map
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClusterBootstrap = exports.ClusterBootstrapStarter = void 0;
|
|
4
|
-
const bootstrap_1 = require("./bootstrap");
|
|
5
|
-
const cp_1 = require("../fork/cp");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
class ClusterBootstrapStarter extends bootstrap_1.BootstrapStarter {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(...arguments);
|
|
10
|
-
this.globalOptions = {};
|
|
11
|
-
}
|
|
12
|
-
async init() {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
async run() {
|
|
16
|
-
this.clusterManager = new cp_1.ClusterManager({
|
|
17
|
-
exec: (0, path_1.join)(__dirname, 'bootstrap'),
|
|
18
|
-
...this.globalOptions,
|
|
19
|
-
});
|
|
20
|
-
await this.clusterManager.start();
|
|
21
|
-
}
|
|
22
|
-
async stop() {
|
|
23
|
-
await this.clusterManager.close();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.ClusterBootstrapStarter = ClusterBootstrapStarter;
|
|
27
|
-
class ClusterBootstrap extends bootstrap_1.Bootstrap {
|
|
28
|
-
/**
|
|
29
|
-
* set global configuration for midway
|
|
30
|
-
* @param configuration
|
|
31
|
-
*/
|
|
32
|
-
static configure(configuration = {}) {
|
|
33
|
-
return super.configure(configuration);
|
|
34
|
-
}
|
|
35
|
-
static getStarter() {
|
|
36
|
-
if (!this.starter) {
|
|
37
|
-
this.starter = new ClusterBootstrapStarter();
|
|
38
|
-
}
|
|
39
|
-
return this.starter;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.ClusterBootstrap = ClusterBootstrap;
|
|
43
|
-
//# sourceMappingURL=cluster.js.map
|
package/dist/fork/thread.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ThreadOptions } from '../interface';
|
|
3
|
-
import { AbstractForkManager } from './base';
|
|
4
|
-
import type { Worker as ThreadWorker } from 'worker_threads';
|
|
5
|
-
export declare class ThreadManager extends AbstractForkManager<ThreadWorker, ThreadOptions> {
|
|
6
|
-
readonly options: ThreadOptions;
|
|
7
|
-
private exitListener;
|
|
8
|
-
constructor(options?: ThreadOptions);
|
|
9
|
-
createWorker(): ThreadWorker;
|
|
10
|
-
bindWorkerDisconnect(listener: (worker: ThreadWorker) => void): void;
|
|
11
|
-
bindWorkerExit(listener: (worker: ThreadWorker, code: any, signal: any) => void): void;
|
|
12
|
-
getWorkerId(worker: ThreadWorker): any;
|
|
13
|
-
isWorkerDead(worker: ThreadWorker): boolean;
|
|
14
|
-
closeWorker(worker: ThreadWorker): Promise<void>;
|
|
15
|
-
createEventBus(): any;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=thread.d.ts.map
|