mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 15:38:19 -07:00
Kill flow subthread on worker exit
This commit is contained in:
parent
c7e22c9648
commit
3333d2a10c
1 changed files with 37 additions and 4 deletions
|
|
@ -241,6 +241,30 @@ class CLI {
|
|||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
|
||||
killThread = (thread:any): void => {
|
||||
const killArray = [
|
||||
'SIGKILL',
|
||||
'SIGHUP',
|
||||
'SIGTERM',
|
||||
'SIGINT',
|
||||
];
|
||||
|
||||
try {
|
||||
thread.kill();
|
||||
} catch (err) {
|
||||
// err
|
||||
}
|
||||
|
||||
killArray.forEach((com: string) => {
|
||||
try {
|
||||
thread.kill(com);
|
||||
} catch (err) {
|
||||
// err
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
runCli = async (): Promise<{
|
||||
cliExitCode: number,
|
||||
errorLogFull: string[],
|
||||
|
|
@ -249,7 +273,6 @@ class CLI {
|
|||
|
||||
const errorLogFull: string[] = [];
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
this.config.jobLog(`Running ${this.config.cli} ${this.config.spawnArgs.join(' ')}`);
|
||||
const cliExitCode: number = await new Promise((resolve) => {
|
||||
try {
|
||||
|
|
@ -257,16 +280,26 @@ class CLI {
|
|||
const spawnArgs = this.config.spawnArgs.map((row) => row.trim()).filter((row) => row !== '');
|
||||
const thread = childProcess.spawn(this.config.cli, spawnArgs, opts);
|
||||
|
||||
process.on('exit', () => {
|
||||
try {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Main thread exiting, cleaning up running CLI');
|
||||
this.killThread(thread);
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Error running cliUtils on Exit function');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
thread.stdout.on('data', (data: string) => {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log(data.toString());
|
||||
errorLogFull.push(data.toString());
|
||||
this.parseOutput(data);
|
||||
});
|
||||
|
||||
thread.stderr.on('data', (data: string) => {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log(data.toString());
|
||||
errorLogFull.push(data.toString());
|
||||
this.parseOutput(data);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue