Browse Source
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
pull/7571/head
Andrew Shvayka
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
17 additions and
9 deletions
-
msa/js-executor/queue/kafkaTemplate.ts
-
msa/js-executor/server.ts
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|