Skip to content

Commit bbcab80

Browse files
feat: remove onExit method
BREAKING CHANGE: remove onExit method, move logic to helpers launcher
1 parent b93a106 commit bbcab80

File tree

4 files changed

+1
-61
lines changed

4 files changed

+1
-61
lines changed

__tests__/services/abstract-microservice-test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,6 @@ describe('services/abstract-microservice', () => {
138138
.lengthOf(1);
139139
});
140140

141-
it('should correct add onExit handler', () => {
142-
const onExitHandler = sinon.spy(() => undefined);
143-
144-
ms.onExit(onExitHandler);
145-
146-
// @ts-ignore
147-
process.emit('SIGINT', 1);
148-
149-
expect(onExitHandler).calledOnceWith(1);
150-
});
151-
152-
it('should correct catch onExit handler error', () => {
153-
const onExitHandler = sinon.spy(() => {
154-
throw new Error('Hello');
155-
});
156-
157-
ms.onExit(onExitHandler);
158-
159-
// @ts-ignore
160-
process.emit('SIGINT', 1);
161-
162-
expect(onExitHandler).to.throw();
163-
});
164-
165141
it('should correct return connection string (SRV)', async () => {
166142
const srvHost = 'http://srv.local';
167143

src/constants/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ export const LOG_INFO_COLOR = '\x1b[32m%s\x1b[0m'; // green
77

88
export const LOG_ERROR_COLOR = '\x1b[31m%s\x1b[0m'; // red
99

10-
export const PROCESS_EXIT_EVENT_TYPES = [
11-
// 'exit',
12-
'SIGINT',
13-
'SIGUSR1',
14-
'SIGUSR2',
15-
'uncaughtException',
16-
'SIGTERM',
17-
];
18-
1910
export enum EXCEPTION_CODE {
2011
ENDPOINT_EXCEPTION = -33000,
2112
PARSE_ERROR = -32700,

src/interfaces/services/i-abstract-microservice.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ interface IInnerRequestParams {
3434
isThrowError?: boolean;
3535
}
3636

37-
type ProcessExitHandler = (eventOrExitCodeOrError: Error | number) => void | Promise<void>;
38-
3937
type MiddlewareData<TParams = Record<string, any>, TPayload = Record<string, any>> = {
4038
task: MicroserviceRequest<TParams, TPayload>;
4139
result?: IMicroserviceResponse<TParams>['result'];
@@ -127,7 +125,6 @@ export {
127125
IAbstractMicroserviceOptions,
128126
IAbstractMicroserviceParams,
129127
IInnerRequestParams,
130-
ProcessExitHandler,
131128
IMiddlewares,
132129
MiddlewareData,
133130
MiddlewareType,

src/services/abstract-microservice.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import http from 'http';
33
import axios from 'axios';
44
import _ from 'lodash';
55
import { v4 as uuidv4 } from 'uuid';
6-
import { EXCEPTION_CODE, PROCESS_EXIT_EVENT_TYPES } from '@constants/index';
6+
import { EXCEPTION_CODE } from '@constants/index';
77
import BaseException from '@core/base-exception';
88
import MicroserviceRequest from '@core/microservice-request';
99
import MicroserviceResponse from '@core/microservice-response';
@@ -31,7 +31,6 @@ import type {
3131
MiddlewareClientRequest,
3232
MiddlewareData,
3333
MiddlewareHandler,
34-
ProcessExitHandler,
3534
} from '@interfaces/services/i-abstract-microservice';
3635
import { MiddlewareType } from '@interfaces/services/i-abstract-microservice';
3736
import type { TJsonRPC } from '@interfaces/services/i-gateway';
@@ -227,29 +226,6 @@ abstract class AbstractMicroservice {
227226
return this;
228227
}
229228

230-
/**
231-
* Add process exit handler
232-
* E.g. for close DB connection etc.
233-
*/
234-
public onExit(handler: ProcessExitHandler): void {
235-
PROCESS_EXIT_EVENT_TYPES.forEach((eventType) => {
236-
process.once(eventType, (eventOrExitCodeOrError: Error | number) => {
237-
void (async () => {
238-
try {
239-
await handler(eventOrExitCodeOrError);
240-
} catch (e) {
241-
this.logDriver(
242-
() => `Process killed with error: ${e.message as string}`,
243-
LogType.ERROR,
244-
);
245-
}
246-
247-
process.exit(Number(eventOrExitCodeOrError) || 1);
248-
})();
249-
});
250-
});
251-
}
252-
253229
/**
254230
* Validate JSON RPC request
255231
* @private

0 commit comments

Comments
 (0)