mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
Refactor thread kill
This commit is contained in:
parent
3333d2a10c
commit
d1ca9eeb93
1 changed files with 22 additions and 14 deletions
|
|
@ -274,24 +274,30 @@ class CLI {
|
|||
const errorLogFull: string[] = [];
|
||||
|
||||
this.config.jobLog(`Running ${this.config.cli} ${this.config.spawnArgs.join(' ')}`);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
|
||||
let thread: any;
|
||||
|
||||
process.on('exit', () => {
|
||||
if (thread) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const cliExitCode: number = await new Promise((resolve) => {
|
||||
try {
|
||||
const opts = this.config.spawnOpts || {};
|
||||
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 = childProcess.spawn(this.config.cli, spawnArgs, opts);
|
||||
|
||||
thread.stdout.on('data', (data: string) => {
|
||||
errorLogFull.push(data.toString());
|
||||
|
|
@ -328,6 +334,8 @@ class CLI {
|
|||
}
|
||||
});
|
||||
|
||||
thread = undefined;
|
||||
|
||||
if (!this.config.logFullCliOutput) {
|
||||
this.config.jobLog(errorLogFull.slice(-1000).join(''));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue