Merge pull request #7555 from smatvienko-tb/fix/js-executor_lifecycle_exit
[3.4.2] js-executor - improved lifecycle events and added kill for crash event
This commit is contained in:
commit
ded5513e29
@ -30,6 +30,8 @@ import {
|
|||||||
TopicMessages
|
TopicMessages
|
||||||
} from 'kafkajs';
|
} from 'kafkajs';
|
||||||
|
|
||||||
|
import process, { kill, exit } from 'process';
|
||||||
|
|
||||||
export class KafkaTemplate implements IQueue {
|
export class KafkaTemplate implements IQueue {
|
||||||
|
|
||||||
private logger = _logger(`kafkaTemplate`);
|
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}`);
|
this.logger.error(`Got consumer CRASH event, should restart: ${e.payload.restart}`);
|
||||||
if (!e.payload.restart) {
|
if (!e.payload.restart) {
|
||||||
this.logger.error('Going to exit due to not retryable error!');
|
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();
|
await this.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -253,6 +256,7 @@ export class KafkaTemplate implements IQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.logger.info('Kafka resources stopped.');
|
this.logger.info('Kafka resources stopped.');
|
||||||
|
exit(0); //same as in version before
|
||||||
}
|
}
|
||||||
|
|
||||||
private async disconnectProducer(): Promise<void> {
|
private async disconnectProducer(): Promise<void> {
|
||||||
|
|||||||
@ -81,15 +81,19 @@ process.on('exit', (code: number) => {
|
|||||||
|
|
||||||
async function exit(status: number) {
|
async function exit(status: number) {
|
||||||
logger.info('Exiting with status: %d ...', status);
|
logger.info('Exiting with status: %d ...', status);
|
||||||
if (httpServer) {
|
try {
|
||||||
const _httpServer = httpServer;
|
if (httpServer) {
|
||||||
httpServer = null;
|
const _httpServer = httpServer;
|
||||||
await _httpServer.stop();
|
httpServer = null;
|
||||||
}
|
await _httpServer.stop();
|
||||||
if (queues) {
|
}
|
||||||
const _queues = queues;
|
if (queues) {
|
||||||
queues = null;
|
const _queues = queues;
|
||||||
await _queues.destroy();
|
queues = null;
|
||||||
|
await _queues.destroy();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Error on exit');
|
||||||
}
|
}
|
||||||
process.exit(status);
|
process.exit(status);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user