js-executor - improved lifecycle events and added kill for crash event
This commit is contained in:
parent
6c9ad0399d
commit
5776f5b39b
@ -30,6 +30,8 @@ import {
|
||||
TopicMessages
|
||||
} from 'kafkajs';
|
||||
|
||||
import process, { kill, exit } from 'process';
|
||||
|
||||
export class KafkaTemplate implements IQueue {
|
||||
|
||||
private logger = _logger(`kafkaTemplate`);
|
||||
@ -122,6 +124,7 @@ export class KafkaTemplate implements IQueue {
|
||||
this.logger.error(`Got consumer CRASH event, should restart: ${e.payload.restart}`);
|
||||
if (!e.payload.restart) {
|
||||
this.logger.error('Going to exit due to not retryable error!');
|
||||
kill(process.pid, 'SIGTERM'); //sending signal to myself process to trigger the handler
|
||||
await this.destroy();
|
||||
}
|
||||
});
|
||||
@ -253,6 +256,7 @@ export class KafkaTemplate implements IQueue {
|
||||
}
|
||||
}
|
||||
this.logger.info('Kafka resources stopped.');
|
||||
exit(0); //same as in version before
|
||||
}
|
||||
|
||||
private async disconnectProducer(): Promise<void> {
|
||||
|
||||
@ -81,15 +81,19 @@ process.on('exit', (code: number) => {
|
||||
|
||||
async function exit(status: number) {
|
||||
logger.info('Exiting with status: %d ...', status);
|
||||
if (httpServer) {
|
||||
const _httpServer = httpServer;
|
||||
httpServer = null;
|
||||
await _httpServer.stop();
|
||||
}
|
||||
if (queues) {
|
||||
const _queues = queues;
|
||||
queues = null;
|
||||
await _queues.destroy();
|
||||
try {
|
||||
if (httpServer) {
|
||||
const _httpServer = httpServer;
|
||||
httpServer = null;
|
||||
await _httpServer.stop();
|
||||
}
|
||||
if (queues) {
|
||||
const _queues = queues;
|
||||
queues = null;
|
||||
await _queues.destroy();
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('Error on exit');
|
||||
}
|
||||
process.exit(status);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user