fix(core): update
This commit is contained in:
21
ts/index.ts
21
ts/index.ts
@ -3,7 +3,8 @@ import * as plugins from './smartexit.plugins';
|
||||
import { ora } from './smartexit.logging';
|
||||
|
||||
export class SmartExit {
|
||||
public processesToEnd = new plugins.lik.Objectmap<plugins.childProcess.ChildProcess>();
|
||||
public processesToEnd = new plugins.lik.ObjectMap<plugins.childProcess.ChildProcess>();
|
||||
public cleanupFunctions = new plugins.lik.ObjectMap<() => Promise<any>>();
|
||||
|
||||
/**
|
||||
* adds a process to be exited
|
||||
@ -13,6 +14,10 @@ export class SmartExit {
|
||||
this.processesToEnd.add(childProcessArg);
|
||||
}
|
||||
|
||||
public addCleanupFunction(cleanupFunctionArg: () => Promise<any>) {
|
||||
this.cleanupFunctions.add(cleanupFunctionArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a process to be exited
|
||||
*/
|
||||
@ -25,7 +30,7 @@ export class SmartExit {
|
||||
if (this.processesToEnd.getArray().length > 0) {
|
||||
ora.text('found remaining child processes');
|
||||
let counter = 1;
|
||||
this.processesToEnd.forEach(async childProcessArg => {
|
||||
this.processesToEnd.forEach(async (childProcessArg) => {
|
||||
const pid = childProcessArg.pid;
|
||||
ora.text(`killing process #${counter} with pid ${pid}`);
|
||||
plugins.smartdelay.delayFor(10000).then(() => {
|
||||
@ -35,12 +40,18 @@ export class SmartExit {
|
||||
process.kill(pid, 'SIGKILL');
|
||||
});
|
||||
process.kill(pid, 'SIGINT');
|
||||
|
||||
|
||||
counter++;
|
||||
});
|
||||
} else {
|
||||
ora.text(`Everything looks clean. Ready to exit!`);
|
||||
ora.text(`ChildProcesses look clean.`);
|
||||
}
|
||||
if (this.cleanupFunctions.getArray.length > 0) {
|
||||
this.cleanupFunctions.forEach(async cleanupFunction => {
|
||||
await cleanupFunction();
|
||||
})
|
||||
}
|
||||
ora.text(`Ready to exit!`);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
@ -63,7 +74,7 @@ export class SmartExit {
|
||||
});
|
||||
|
||||
//catch uncaught exceptions, trace, then exit normally
|
||||
process.on('uncaughtException', async err => {
|
||||
process.on('uncaughtException', async (err) => {
|
||||
ora.text('SMARTEXIT: uncaught exception...');
|
||||
console.log(err);
|
||||
await this.killAll();
|
||||
|
@ -1,3 +1,3 @@
|
||||
import * as plugins from './smartexit.plugins';
|
||||
|
||||
export const ora = new plugins.smartlogSourceOra.SmartlogSourceOra();
|
||||
export const ora = new plugins.smartlogSourceOra.SmartlogSourceOra();
|
||||
|
@ -8,4 +8,4 @@ import * as lik from '@pushrocks/lik';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartlogSourceOra from '@pushrocks/smartlog-source-ora';
|
||||
|
||||
export { lik, smartdelay, smartlogSourceOra};
|
||||
export { lik, smartdelay, smartlogSourceOra };
|
||||
|
Reference in New Issue
Block a user