exodus-framework 2.1.1002 → 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.
@@ -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,MAAM,IAAI,CAAC;AAC1B,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAC5C,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;AACjD,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;AACxC,KAAK,WAAW,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,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E,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"}
@@ -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,6 +18,9 @@ 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
25
  protected onClusterUncaughtException(_err: Error): void;
23
26
  protected onMasterUncaughtException(_err: Error): void;
@@ -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,OAAO,MAAM,MAAM,UAAU,CAAC;AAS9B,uBAAe,OAAQ,SAAQ,MAAM;IACnC,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,UAAU,CAAU;;IAS5B,OAAO,CAAC,wBAAwB;IAWhC,SAAS,CAAC,MAAM;IAYhB,SAAS,CAAC,aAAa;IACvB,SAAS,CAAC,YAAY;IAOtB,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM;IAI9B,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM;IAGrC,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM;IAGpC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAGvE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAM1C,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAIjD,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAMhD,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAM3C,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO;IAIlD,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,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T(signal));
30
30
  _event.default.registerProcessSIGTERMHandle(signal => this.onSIGTERM(signal));
31
+ _event.default.registerProcessSIGUSR2Handle(signal => this.onSIGUSR2(signal));
31
32
  _event.default.registerProcessExceptionHandle(err => this.onUncaughtException(err));
32
33
  _event.default.registerProcessExitHandle(code => this.onExit(code));
33
34
  _event.default.registerProcessRejectionHandle((reason, promise) => this.onUnhandledRejection(reason, promise));
@@ -68,14 +69,8 @@ class Managed extends _system.default {
68
69
  if (this.isMaster()) this.onMasterSIGINT(_signal);
69
70
  if (this.isCluster()) this.onClusterSIGINT(_signal);
70
71
  }
71
- onClusterSIGINT(_signal) {
72
- this.log('Processo encerrado pelo usuário', 'especial');
73
- process.exit(0);
74
- }
75
- onMasterSIGINT(_signal) {
76
- this.log('Processo encerrado pelo usuário', 'especial');
77
- process.exit(0);
78
- }
72
+ onClusterSIGINT(_signal) {}
73
+ onMasterSIGINT(_signal) {}
79
74
 
80
75
  //# SIGTERM
81
76
  onSIGTERM(_signal) {
@@ -83,38 +78,32 @@ class Managed extends _system.default {
83
78
  if (this.isMaster()) this.onMasterSIGTERM(_signal);
84
79
  if (this.isCluster()) this.onClusterSIGTERM(_signal);
85
80
  }
86
- onClusterSIGTERM(_signal) {
87
- this.log('Processo encerrado pelo sistema', 'especial');
88
- process.exit(0);
89
- }
90
- onMasterSIGTERM(_signal) {
91
- this.log('Processo encerrado pelo sistema', 'especial');
92
- process.exit(0);
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);
93
88
  }
89
+ onClusterSIGUSR2(_signal) {}
90
+ onMasterSIGUSR2(_signal) {}
94
91
 
95
92
  //# UNCAUGHT EXCEPTION
96
93
  onUncaughtException(_err) {
97
94
  if (this.isMaster()) this.onMasterUncaughtException(_err);
98
95
  if (this.isCluster()) this.onClusterUncaughtException(_err);
99
96
  }
100
- onClusterUncaughtException(_err) {
101
- //
102
- }
103
- onMasterUncaughtException(_err) {
104
- //
105
- }
97
+ onClusterUncaughtException(_err) {}
98
+ onMasterUncaughtException(_err) {}
106
99
 
107
100
  //# UNHANDLED REJECTION
108
101
  onUnhandledRejection(_reason, _promise) {
109
102
  if (this.isMaster()) this.onMasterUnhandledRejection(_reason, _promise);
110
103
  if (this.isCluster()) this.onClusterUnhandledRejection(_reason, _promise);
111
104
  }
112
- onClusterUnhandledRejection(_reason, _promise) {
113
- //
114
- }
115
- onMasterUnhandledRejection(_reason, _promise) {
116
- //
117
- }
105
+ onClusterUnhandledRejection(_reason, _promise) {}
106
+ onMasterUnhandledRejection(_reason, _promise) {}
118
107
 
119
108
  //# Utils
120
109
  isMaster() {
@@ -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,10 +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;
14
19
  protected onClusterUncaughtException(err: Error): void;
15
20
  protected onMasterUncaughtException(err: Error): void;
16
21
  protected onClusterUnhandledRejection(reason: unknown, promise: Promise<unknown>): void;
17
22
  protected onMasterUnhandledRejection(reason: unknown, promise: Promise<unknown>): void;
23
+ private isCriticalRejection;
24
+ shutdown(reason?: string): Promise<void>;
25
+ private gracefulShutdown;
18
26
  }
19
27
  export default Exodus;
20
28
  //# sourceMappingURL=exodus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exodus.d.ts","sourceRoot":"","sources":["../../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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
@@ -11,6 +11,7 @@ var _event = _interopRequireDefault(require("./classes/event"));
11
11
  var _managed = _interopRequireDefault(require("./classes/managed"));
12
12
  var _core = _interopRequireDefault(require("./core"));
13
13
  var _logger2 = _interopRequireDefault(require("../utils/logger"));
14
+ var _process = require("process");
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  /**
16
17
  * Classe da aplicação principal
@@ -21,6 +22,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
21
22
  */
22
23
  class Exodus extends _managed.default {
23
24
  services;
25
+ isShuttingDown = false;
24
26
  static startedAt;
25
27
  constructor(settings) {
26
28
  super();
@@ -102,18 +104,45 @@ class Exodus extends _managed.default {
102
104
  return Exodus.startedAt;
103
105
  }
104
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
+
105
130
  //# UNCAUGHT EXCEPTION
106
131
  onClusterUncaughtException(err) {
107
132
  const msg = `Uma excessão ocorreu no cluster: ${err.message}`;
108
133
  this.log(msg, 'danger');
109
134
  (0, _logger2.default)().fatal(err, msg);
110
- throw err;
135
+
136
+ // Inicia graceful shutdown para cluster
137
+ this.gracefulShutdown('UNCAUGHT_EXCEPTION', err);
111
138
  }
112
139
  onMasterUncaughtException(err) {
113
140
  const msg = `Uma excessão ocorreu no master: ${err.message}`;
114
141
  this.log(msg, 'danger');
115
142
  (0, _logger2.default)().fatal(err, msg);
116
- throw err;
143
+
144
+ // Inicia graceful shutdown para master
145
+ this.gracefulShutdown('UNCAUGHT_EXCEPTION', err);
117
146
  }
118
147
 
119
148
  //# UNHANDLED REJECTION
@@ -124,6 +153,12 @@ class Exodus extends _managed.default {
124
153
  reason,
125
154
  promise
126
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
+ }
127
162
  }
128
163
  onMasterUnhandledRejection(reason, promise) {
129
164
  const msg = `Erro não tratado em uma promisse no master: ${reason}`;
@@ -132,6 +167,100 @@ class Exodus extends _managed.default {
132
167
  reason,
133
168
  promise
134
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
+ }
135
264
  }
136
265
  }
137
266
  var _default = exports.default = Exodus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.1.01002",
3
+ "version": "2.1.1003",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",