fix(core): update
This commit is contained in:
22
ts/index.ts
22
ts/index.ts
@ -1,7 +1,5 @@
|
||||
import * as plugins from './smartexit.plugins';
|
||||
|
||||
import { ora } from './smartexit.logging';
|
||||
|
||||
export class SmartExit {
|
||||
public processesToEnd = new plugins.lik.ObjectMap<plugins.childProcess.ChildProcess>();
|
||||
public cleanupFunctions = new plugins.lik.ObjectMap<() => Promise<any>>();
|
||||
@ -26,13 +24,13 @@ export class SmartExit {
|
||||
}
|
||||
|
||||
public async killAll() {
|
||||
ora.text('Checking for remaining child processes before exit...');
|
||||
console.log('Checking for remaining child processes before exit...');
|
||||
if (this.processesToEnd.getArray().length > 0) {
|
||||
ora.text('found remaining child processes');
|
||||
console.log('found remaining child processes');
|
||||
let counter = 1;
|
||||
this.processesToEnd.forEach(async (childProcessArg) => {
|
||||
const pid = childProcessArg.pid;
|
||||
ora.text(`killing process #${counter} with pid ${pid}`);
|
||||
console.log(`killing process #${counter} with pid ${pid}`);
|
||||
plugins.smartdelay.delayFor(10000).then(() => {
|
||||
if (childProcessArg.killed) {
|
||||
return;
|
||||
@ -44,38 +42,38 @@ export class SmartExit {
|
||||
counter++;
|
||||
});
|
||||
} else {
|
||||
ora.text(`ChildProcesses look clean.`);
|
||||
console.log(`ChildProcesses look clean.`);
|
||||
}
|
||||
if (this.cleanupFunctions.getArray.length > 0) {
|
||||
this.cleanupFunctions.forEach(async cleanupFunction => {
|
||||
await cleanupFunction();
|
||||
})
|
||||
}
|
||||
ora.text(`Ready to exit!`);
|
||||
console.log(`Ready to exit!`);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
// do app specific cleaning before exiting
|
||||
process.on('exit', async (code) => {
|
||||
if (code === 0) {
|
||||
ora.text('Process wants to exit');
|
||||
console.log('Process wants to exit');
|
||||
await this.killAll();
|
||||
ora.finishSuccess('Exited ok!');
|
||||
console.log('Exited ok!');
|
||||
} else {
|
||||
ora.finishFail('Exited NOT OK!');
|
||||
console.error('Exited NOT OK!');
|
||||
}
|
||||
});
|
||||
|
||||
// catch ctrl+c event and exit normally
|
||||
process.on('SIGINT', async () => {
|
||||
ora.text('Ctrl-C... or SIGINT signal received!');
|
||||
console.log('Ctrl-C... or SIGINT signal received!');
|
||||
await this.killAll();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
//catch uncaught exceptions, trace, then exit normally
|
||||
process.on('uncaughtException', async (err) => {
|
||||
ora.text('SMARTEXIT: uncaught exception...');
|
||||
console.log('SMARTEXIT: uncaught exception...');
|
||||
console.log(err);
|
||||
await this.killAll();
|
||||
process.exit(1);
|
||||
|
@ -1,3 +0,0 @@
|
||||
import * as plugins from './smartexit.plugins';
|
||||
|
||||
export const ora = new plugins.smartlogSourceOra.SmartlogSourceOra();
|
Reference in New Issue
Block a user