exodus-framework 2.1.1 → 2.1.1003
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/lib/app/classes/event.d.ts +2 -0
- package/lib/app/classes/event.d.ts.map +1 -1
- package/lib/app/classes/event.js +9 -0
- package/lib/app/classes/managed.d.ts +7 -4
- package/lib/app/classes/managed.d.ts.map +1 -1
- package/lib/app/classes/managed.js +16 -46
- package/lib/app/exodus.d.ts +12 -0
- package/lib/app/exodus.d.ts.map +1 -1
- package/lib/app/exodus.js +162 -0
- package/package.json +1 -1
@@ -14,6 +14,7 @@ declare class ProcessEmitterManager extends System {
|
|
14
14
|
private static clusterExitHandles;
|
15
15
|
private static processSIGINTHandles;
|
16
16
|
private static processSIGTERMHandles;
|
17
|
+
private static processSIGUSR2Handles;
|
17
18
|
private static processExceptionHandles;
|
18
19
|
private static processRejectionHandles;
|
19
20
|
private static processExitHandles;
|
@@ -27,6 +28,7 @@ declare class ProcessEmitterManager extends System {
|
|
27
28
|
static registerProcessRejectionHandle(handle: cbRejection): void;
|
28
29
|
static registerProcessExitHandle(handle: cbProcessExit): void;
|
29
30
|
static registerProcessMessageHandle(handle: cbMessage): void;
|
31
|
+
static registerProcessSIGUSR2Handle(handle: cbSignal): void;
|
30
32
|
static Start(): void;
|
31
33
|
}
|
32
34
|
export default ProcessEmitterManager;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/app/classes/event.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AACrE,KAAK,OAAO,GAAG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O,CAAC,MAAM,CAAC,uBAAuB,CAAqB;IAC3D,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAuB;IACxD,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAmB;IAEvD,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,OAAO;IAGhD,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM;IAG9C,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM;IAG/C,MAAM,CAAC,2BAA2B,CAAC,MAAM,EAAE,QAAQ;IAGnD,MAAM,CAAC,4BAA4B,CAAC,MAAM,EAAE,QAAQ;IAGpD,MAAM,CAAC,8BAA8B,CAAC,MAAM,EAAE,WAAW;IAGzD,MAAM,CAAC,8BAA8B,CAAC,MAAM,EAAE,WAAW;IAGzD,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,aAAa;IAGtD,MAAM,CAAC,4BAA4B,CAAC,MAAM,EAAE,SAAS;IAGrD,MAAM,CAAC,4BAA4B,CAAC,MAAM,EAAE,QAAQ;IAIpD,MAAM,CAAC,KAAK;CA6Db;AAED,eAAe,qBAAqB,CAAC"}
|
package/lib/app/classes/event.js
CHANGED
@@ -19,6 +19,7 @@ class ProcessEmitterManager extends _system.default {
|
|
19
19
|
static clusterExitHandles = [];
|
20
20
|
static processSIGINTHandles = [];
|
21
21
|
static processSIGTERMHandles = [];
|
22
|
+
static processSIGUSR2Handles = [];
|
22
23
|
static processExceptionHandles = [];
|
23
24
|
static processRejectionHandles = [];
|
24
25
|
static processExitHandles = [];
|
@@ -50,6 +51,9 @@ class ProcessEmitterManager extends _system.default {
|
|
50
51
|
static registerProcessMessageHandle(handle) {
|
51
52
|
this.processMessageHandles.push(handle);
|
52
53
|
}
|
54
|
+
static registerProcessSIGUSR2Handle(handle) {
|
55
|
+
this.processSIGUSR2Handles.push(handle);
|
56
|
+
}
|
53
57
|
static Start() {
|
54
58
|
for (const cb of this.workerStartHandles) {
|
55
59
|
if (cb) cb();
|
@@ -76,6 +80,11 @@ class ProcessEmitterManager extends _system.default {
|
|
76
80
|
if (cb) cb(signal);
|
77
81
|
}
|
78
82
|
});
|
83
|
+
process.on('SIGUSR2', signal => {
|
84
|
+
for (const cb of this.processSIGUSR2Handles) {
|
85
|
+
if (cb) cb(signal);
|
86
|
+
}
|
87
|
+
});
|
79
88
|
process.on('uncaughtException', err => {
|
80
89
|
for (const cb of this.processExceptionHandles) {
|
81
90
|
if (cb) cb(err);
|
@@ -18,12 +18,15 @@ declare abstract class Managed extends System {
|
|
18
18
|
protected onSIGTERM(_signal: NodeJS.Signals): void;
|
19
19
|
protected onClusterSIGTERM(_signal: NodeJS.Signals): void;
|
20
20
|
protected onMasterSIGTERM(_signal: NodeJS.Signals): void;
|
21
|
+
protected onSIGUSR2(_signal: NodeJS.Signals): void;
|
22
|
+
protected onClusterSIGUSR2(_signal: NodeJS.Signals): void;
|
23
|
+
protected onMasterSIGUSR2(_signal: NodeJS.Signals): void;
|
21
24
|
protected onUncaughtException(_err: Error): void;
|
22
|
-
protected onClusterUncaughtException(
|
23
|
-
protected onMasterUncaughtException(
|
25
|
+
protected onClusterUncaughtException(_err: Error): void;
|
26
|
+
protected onMasterUncaughtException(_err: Error): void;
|
24
27
|
protected onUnhandledRejection(_reason: unknown, _promise: Promise<unknown>): void;
|
25
|
-
protected onClusterUnhandledRejection(
|
26
|
-
protected onMasterUnhandledRejection(
|
28
|
+
protected onClusterUnhandledRejection(_reason: unknown, _promise: Promise<unknown>): void;
|
29
|
+
protected onMasterUnhandledRejection(_reason: unknown, _promise: Promise<unknown>): void;
|
27
30
|
protected isMaster(): boolean;
|
28
31
|
protected isCluster(): boolean;
|
29
32
|
protected getWorkers(): NodeJS.Dict<Worker>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"managed.d.ts","sourceRoot":"","sources":["../../../src/app/classes/managed.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAG1C,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IAAI,EAAE,KAAK;IAIzC,SAAS,CAAC,0BAA0B,CAAC,IAAI,EAAE,KAAK;IAChD,SAAS,CAAC,yBAAyB,CAAC,IAAI,EAAE,KAAK;IAG/C,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC;IAI3E,SAAS,CAAC,2BAA2B,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC;IAClF,SAAS,CAAC,0BAA0B,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC;IAGjF,SAAS,CAAC,QAAQ;IAGlB,SAAS,CAAC,SAAS;IAKnB,SAAS,CAAC,UAAU;IAGpB,SAAS,CAAC,SAAS;IAMnB,SAAS,CAAC,eAAe;CAG1B;AAED,eAAe,OAAO,CAAC"}
|
@@ -8,7 +8,6 @@ var _cluster = _interopRequireDefault(require("cluster"));
|
|
8
8
|
var _process = require("process");
|
9
9
|
var _event = _interopRequireDefault(require("./event"));
|
10
10
|
var _system = _interopRequireDefault(require("./system"));
|
11
|
-
var _logger = _interopRequireDefault(require("../../utils/logger"));
|
12
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
13
12
|
/**
|
14
13
|
* Disponibiliza ações de controle de clusters, incluindo comunicação básica
|
@@ -29,6 +28,7 @@ class Managed extends _system.default {
|
|
29
28
|
bindProcessEventHandlers() {
|
30
29
|
_event.default.registerProcessSIGINTHandle(signal => this.onSIGINT(signal));
|
31
30
|
_event.default.registerProcessSIGTERMHandle(signal => this.onSIGTERM(signal));
|
31
|
+
_event.default.registerProcessSIGUSR2Handle(signal => this.onSIGUSR2(signal));
|
32
32
|
_event.default.registerProcessExceptionHandle(err => this.onUncaughtException(err));
|
33
33
|
_event.default.registerProcessExitHandle(code => this.onExit(code));
|
34
34
|
_event.default.registerProcessRejectionHandle((reason, promise) => this.onUnhandledRejection(reason, promise));
|
@@ -69,14 +69,8 @@ class Managed extends _system.default {
|
|
69
69
|
if (this.isMaster()) this.onMasterSIGINT(_signal);
|
70
70
|
if (this.isCluster()) this.onClusterSIGINT(_signal);
|
71
71
|
}
|
72
|
-
onClusterSIGINT(_signal) {
|
73
|
-
|
74
|
-
process.exit(0);
|
75
|
-
}
|
76
|
-
onMasterSIGINT(_signal) {
|
77
|
-
this.log('Processo encerrado pelo usuário', 'especial');
|
78
|
-
process.exit(0);
|
79
|
-
}
|
72
|
+
onClusterSIGINT(_signal) {}
|
73
|
+
onMasterSIGINT(_signal) {}
|
80
74
|
|
81
75
|
//# SIGTERM
|
82
76
|
onSIGTERM(_signal) {
|
@@ -84,56 +78,32 @@ class Managed extends _system.default {
|
|
84
78
|
if (this.isMaster()) this.onMasterSIGTERM(_signal);
|
85
79
|
if (this.isCluster()) this.onClusterSIGTERM(_signal);
|
86
80
|
}
|
87
|
-
onClusterSIGTERM(_signal) {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
this.
|
93
|
-
|
81
|
+
onClusterSIGTERM(_signal) {}
|
82
|
+
onMasterSIGTERM(_signal) {}
|
83
|
+
|
84
|
+
//# SIGUSR2
|
85
|
+
onSIGUSR2(_signal) {
|
86
|
+
if (this.isMaster()) this.onMasterSIGUSR2(_signal);
|
87
|
+
if (this.isCluster()) this.onClusterSIGUSR2(_signal);
|
94
88
|
}
|
89
|
+
onClusterSIGUSR2(_signal) {}
|
90
|
+
onMasterSIGUSR2(_signal) {}
|
95
91
|
|
96
92
|
//# UNCAUGHT EXCEPTION
|
97
93
|
onUncaughtException(_err) {
|
98
94
|
if (this.isMaster()) this.onMasterUncaughtException(_err);
|
99
95
|
if (this.isCluster()) this.onClusterUncaughtException(_err);
|
100
96
|
}
|
101
|
-
onClusterUncaughtException(
|
102
|
-
|
103
|
-
this.log(msg, 'danger');
|
104
|
-
(0, _logger.default)().fatal(err, msg);
|
105
|
-
|
106
|
-
// throw err;
|
107
|
-
}
|
108
|
-
onMasterUncaughtException(err) {
|
109
|
-
const msg = `Uma excessão ocorreu no master: ${err.message}`;
|
110
|
-
this.log(msg, 'danger');
|
111
|
-
(0, _logger.default)().fatal(err, msg);
|
112
|
-
|
113
|
-
// throw err;
|
114
|
-
}
|
97
|
+
onClusterUncaughtException(_err) {}
|
98
|
+
onMasterUncaughtException(_err) {}
|
115
99
|
|
116
100
|
//# UNHANDLED REJECTION
|
117
101
|
onUnhandledRejection(_reason, _promise) {
|
118
102
|
if (this.isMaster()) this.onMasterUnhandledRejection(_reason, _promise);
|
119
103
|
if (this.isCluster()) this.onClusterUnhandledRejection(_reason, _promise);
|
120
104
|
}
|
121
|
-
onClusterUnhandledRejection(
|
122
|
-
|
123
|
-
this.log(msg, 'danger');
|
124
|
-
(0, _logger.default)().fatal({
|
125
|
-
reason,
|
126
|
-
promise
|
127
|
-
}, msg);
|
128
|
-
}
|
129
|
-
onMasterUnhandledRejection(reason, promise) {
|
130
|
-
const msg = `Erro não tratado em uma promisse no master: ${reason}`;
|
131
|
-
this.log(msg, 'danger');
|
132
|
-
(0, _logger.default)().fatal({
|
133
|
-
reason,
|
134
|
-
promise
|
135
|
-
}, msg);
|
136
|
-
}
|
105
|
+
onClusterUnhandledRejection(_reason, _promise) {}
|
106
|
+
onMasterUnhandledRejection(_reason, _promise) {}
|
137
107
|
|
138
108
|
//# Utils
|
139
109
|
isMaster() {
|
package/lib/app/exodus.d.ts
CHANGED
@@ -3,6 +3,7 @@ import Managed from './classes/managed';
|
|
3
3
|
import CoreSettings from './settings';
|
4
4
|
declare class Exodus extends Managed {
|
5
5
|
private services;
|
6
|
+
private isShuttingDown;
|
6
7
|
static startedAt: Date;
|
7
8
|
constructor(settings: CoreSettings);
|
8
9
|
start(): Promise<void>;
|
@@ -11,6 +12,17 @@ declare class Exodus extends Managed {
|
|
11
12
|
private initServices;
|
12
13
|
private startService;
|
13
14
|
static getStartedAt(): Date;
|
15
|
+
protected onExit(code: number): void;
|
16
|
+
protected onSIGTERM(signal: NodeJS.Signals): void;
|
17
|
+
protected onSIGINT(signal: NodeJS.Signals): void;
|
18
|
+
protected onSIGUSR2(signal: NodeJS.Signals): void;
|
19
|
+
protected onClusterUncaughtException(err: Error): void;
|
20
|
+
protected onMasterUncaughtException(err: Error): void;
|
21
|
+
protected onClusterUnhandledRejection(reason: unknown, promise: Promise<unknown>): void;
|
22
|
+
protected onMasterUnhandledRejection(reason: unknown, promise: Promise<unknown>): void;
|
23
|
+
private isCriticalRejection;
|
24
|
+
shutdown(reason?: string): Promise<void>;
|
25
|
+
private gracefulShutdown;
|
14
26
|
}
|
15
27
|
export default Exodus;
|
16
28
|
//# sourceMappingURL=exodus.d.ts.map
|
package/lib/app/exodus.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"exodus.d.ts","sourceRoot":"","sources":["../../src/app/exodus.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,OAAO,EAAE,MAAM,GAAG,CAAC;AAG1C,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAExC,OAAO,YAAY,MAAM,YAAY,CAAC;
|
1
|
+
{"version":3,"file":"exodus.d.ts","sourceRoot":"","sources":["../../src/app/exodus.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,OAAO,EAAE,MAAM,GAAG,CAAC;AAG1C,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAExC,OAAO,YAAY,MAAM,YAAY,CAAC;AAWtC,cAAM,MAAO,SAAQ,OAAO;IAC1B,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,cAAc,CAAkB;IACxC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEX,QAAQ,EAAE,YAAY;IAUrB,KAAK;IAwBlB,OAAO,CAAC,cAAc;IAef,QAAQ,CAAC,OAAO,EAAE,OAAO,OAAO;YAGzB,YAAY;YAiBZ,YAAY;IAsB1B,MAAM,CAAC,YAAY,IAAI,IAAI;IAK3B,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM;IAM7B,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO;IAK1C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO;IAKzC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO;IAO1C,SAAS,CAAC,0BAA0B,CAAC,GAAG,EAAE,KAAK;IAS/C,SAAS,CAAC,yBAAyB,CAAC,GAAG,EAAE,KAAK;IAW9C,SAAS,CAAC,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAehF,SAAS,CAAC,0BAA0B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAiB/E,OAAO,CAAC,mBAAmB;IAkBd,QAAQ,CAAC,MAAM,GAAE,MAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;YAGjD,gBAAgB;CAwF/B;AACD,eAAe,MAAM,CAAC"}
|
package/lib/app/exodus.js
CHANGED
@@ -10,6 +10,8 @@ var _logger = _interopRequireDefault(require("../services/logger"));
|
|
10
10
|
var _event = _interopRequireDefault(require("./classes/event"));
|
11
11
|
var _managed = _interopRequireDefault(require("./classes/managed"));
|
12
12
|
var _core = _interopRequireDefault(require("./core"));
|
13
|
+
var _logger2 = _interopRequireDefault(require("../utils/logger"));
|
14
|
+
var _process = require("process");
|
13
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
14
16
|
/**
|
15
17
|
* Classe da aplicação principal
|
@@ -20,6 +22,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
20
22
|
*/
|
21
23
|
class Exodus extends _managed.default {
|
22
24
|
services;
|
25
|
+
isShuttingDown = false;
|
23
26
|
static startedAt;
|
24
27
|
constructor(settings) {
|
25
28
|
super();
|
@@ -100,5 +103,164 @@ class Exodus extends _managed.default {
|
|
100
103
|
static getStartedAt() {
|
101
104
|
return Exodus.startedAt;
|
102
105
|
}
|
106
|
+
|
107
|
+
//# Exit
|
108
|
+
onExit(code) {
|
109
|
+
super.onExit(code);
|
110
|
+
(0, _process.exit)(code);
|
111
|
+
}
|
112
|
+
|
113
|
+
//# SIGNAL HANDLERS
|
114
|
+
onSIGTERM(signal) {
|
115
|
+
super.onSIGTERM(signal);
|
116
|
+
this.log('Recebido SIGTERM. Iniciando graceful shutdown...', 'warning');
|
117
|
+
this.gracefulShutdown('SIGTERM');
|
118
|
+
}
|
119
|
+
onSIGINT(signal) {
|
120
|
+
super.onSIGINT(signal);
|
121
|
+
this.log('Recebido SIGINT (Ctrl+C). Iniciando graceful shutdown...', 'warning');
|
122
|
+
this.gracefulShutdown('SIGINT');
|
123
|
+
}
|
124
|
+
onSIGUSR2(signal) {
|
125
|
+
super.onSIGUSR2(signal);
|
126
|
+
this.log('Recebido SIGUSR2. Iniciando graceful shutdown...', 'warning');
|
127
|
+
this.gracefulShutdown('SIGUSR2');
|
128
|
+
}
|
129
|
+
|
130
|
+
//# UNCAUGHT EXCEPTION
|
131
|
+
onClusterUncaughtException(err) {
|
132
|
+
const msg = `Uma excessão ocorreu no cluster: ${err.message}`;
|
133
|
+
this.log(msg, 'danger');
|
134
|
+
(0, _logger2.default)().fatal(err, msg);
|
135
|
+
|
136
|
+
// Inicia graceful shutdown para cluster
|
137
|
+
this.gracefulShutdown('UNCAUGHT_EXCEPTION', err);
|
138
|
+
}
|
139
|
+
onMasterUncaughtException(err) {
|
140
|
+
const msg = `Uma excessão ocorreu no master: ${err.message}`;
|
141
|
+
this.log(msg, 'danger');
|
142
|
+
(0, _logger2.default)().fatal(err, msg);
|
143
|
+
|
144
|
+
// Inicia graceful shutdown para master
|
145
|
+
this.gracefulShutdown('UNCAUGHT_EXCEPTION', err);
|
146
|
+
}
|
147
|
+
|
148
|
+
//# UNHANDLED REJECTION
|
149
|
+
onClusterUnhandledRejection(reason, promise) {
|
150
|
+
const msg = `Erro não tratado em uma promisse no cluster: ${reason}`;
|
151
|
+
this.log(msg, 'danger');
|
152
|
+
(0, _logger2.default)().fatal({
|
153
|
+
reason,
|
154
|
+
promise
|
155
|
+
}, msg);
|
156
|
+
|
157
|
+
// Para rejection críticas, também faz graceful shutdown
|
158
|
+
if (this.isCriticalRejection(reason)) {
|
159
|
+
this.log('Rejection crítica detectada. Iniciando graceful shutdown...', 'danger');
|
160
|
+
this.gracefulShutdown('CRITICAL_UNHANDLED_REJECTION', reason instanceof Error ? reason : new Error(String(reason)));
|
161
|
+
}
|
162
|
+
}
|
163
|
+
onMasterUnhandledRejection(reason, promise) {
|
164
|
+
const msg = `Erro não tratado em uma promisse no master: ${reason}`;
|
165
|
+
this.log(msg, 'danger');
|
166
|
+
(0, _logger2.default)().fatal({
|
167
|
+
reason,
|
168
|
+
promise
|
169
|
+
}, msg);
|
170
|
+
|
171
|
+
// Para rejection críticas, também faz graceful shutdown
|
172
|
+
if (this.isCriticalRejection(reason)) {
|
173
|
+
this.log('Rejection crítica detectada. Iniciando graceful shutdown...', 'danger');
|
174
|
+
this.gracefulShutdown('CRITICAL_UNHANDLED_REJECTION', reason instanceof Error ? reason : new Error(String(reason)));
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
//# HELPER METHODS
|
179
|
+
isCriticalRejection(reason) {
|
180
|
+
if (!reason) return false;
|
181
|
+
const reasonStr = String(reason).toLowerCase();
|
182
|
+
|
183
|
+
// Lista de erros que consideramos críticos
|
184
|
+
const criticalPatterns = ['econnrefused', 'database connection', 'auth', 'permission denied', 'out of memory', 'disk space', 'network unreachable'];
|
185
|
+
return criticalPatterns.some(pattern => reasonStr.includes(pattern));
|
186
|
+
}
|
187
|
+
async shutdown(reason = 'MANUAL') {
|
188
|
+
return this.gracefulShutdown(reason);
|
189
|
+
}
|
190
|
+
async gracefulShutdown(reason, error) {
|
191
|
+
if (this.isShuttingDown) {
|
192
|
+
this.log('Shutdown já em andamento...', 'warning');
|
193
|
+
return;
|
194
|
+
}
|
195
|
+
this.isShuttingDown = true;
|
196
|
+
const startTime = Date.now();
|
197
|
+
this.log(`Iniciando graceful shutdown. Motivo: ${reason}`, 'warning');
|
198
|
+
try {
|
199
|
+
// Timeout para evitar shutdown infinito
|
200
|
+
const shutdownTimeout = setTimeout(() => {
|
201
|
+
this.log('Timeout no graceful shutdown. Forçando saída...', 'danger');
|
202
|
+
process.exit(1);
|
203
|
+
}, 30000); // 30 segundos
|
204
|
+
|
205
|
+
// Para serviços em ordem reversa
|
206
|
+
const reverseServices = [...this.services].reverse();
|
207
|
+
for (const service of reverseServices) {
|
208
|
+
try {
|
209
|
+
this.log(`Parando serviço: ${service.constructor.name}`, 'info');
|
210
|
+
|
211
|
+
// Se o serviço tem método de cleanup, chama ele
|
212
|
+
if (typeof service.onShutdown === 'function') {
|
213
|
+
await service.onShutdown();
|
214
|
+
}
|
215
|
+
this.log(`Serviço ${service.constructor.name} parado com sucesso`, 'info');
|
216
|
+
} catch (serviceError) {
|
217
|
+
this.log(`Erro ao parar serviço ${service.constructor.name}: ${serviceError.message}`, 'warning');
|
218
|
+
(0, _logger2.default)().error(serviceError, `Erro no shutdown do serviço ${service.constructor.name}`);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
// Fecha conexões de cluster se for master
|
223
|
+
if (this.isMaster()) {
|
224
|
+
this.log('Encerrando clusters...', 'info');
|
225
|
+
_cluster.default.disconnect();
|
226
|
+
|
227
|
+
// Aguarda clusters fecharem graciosamente
|
228
|
+
await new Promise(resolve => {
|
229
|
+
const activeWorkers = Object.keys(_cluster.default.workers || {}).length;
|
230
|
+
if (activeWorkers === 0) {
|
231
|
+
resolve();
|
232
|
+
return;
|
233
|
+
}
|
234
|
+
const checkWorkers = setInterval(() => {
|
235
|
+
const currentWorkers = Object.keys(_cluster.default.workers || {}).length;
|
236
|
+
if (currentWorkers === 0) {
|
237
|
+
clearInterval(checkWorkers);
|
238
|
+
resolve();
|
239
|
+
}
|
240
|
+
}, 100);
|
241
|
+
|
242
|
+
// Timeout para workers
|
243
|
+
setTimeout(() => {
|
244
|
+
clearInterval(checkWorkers);
|
245
|
+
this.log('Timeout aguardando clusters. Forçando encerramento...', 'warning');
|
246
|
+
resolve();
|
247
|
+
}, 10000);
|
248
|
+
});
|
249
|
+
}
|
250
|
+
clearTimeout(shutdownTimeout);
|
251
|
+
const shutdownTime = Date.now() - startTime;
|
252
|
+
this.log(`Graceful shutdown concluído em ${shutdownTime}ms`, 'info');
|
253
|
+
|
254
|
+
// Log final do erro se existir
|
255
|
+
if (error) {
|
256
|
+
(0, _logger2.default)().fatal(error, `Aplicação encerrada devido a: ${reason}`);
|
257
|
+
}
|
258
|
+
process.exit(error ? 1 : 0);
|
259
|
+
} catch (shutdownError) {
|
260
|
+
this.log(`Erro durante graceful shutdown: ${shutdownError.message}`, 'danger');
|
261
|
+
(0, _logger2.default)().fatal(shutdownError, 'Erro crítico durante shutdown');
|
262
|
+
process.exit(1);
|
263
|
+
}
|
264
|
+
}
|
103
265
|
}
|
104
266
|
var _default = exports.default = Exodus;
|