Refactor thread kill

make-only-subtitle-default
HaveAGitGat 2 years ago
parent 3333d2a10c
commit d1ca9eeb93

@ -274,13 +274,12 @@ class CLI {
const errorLogFull: string[] = []; const errorLogFull: string[] = [];
this.config.jobLog(`Running ${this.config.cli} ${this.config.spawnArgs.join(' ')}`); this.config.jobLog(`Running ${this.config.cli} ${this.config.spawnArgs.join(' ')}`);
const cliExitCode: number = await new Promise((resolve) => {
try { // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
const opts = this.config.spawnOpts || {}; let thread: any;
const spawnArgs = this.config.spawnArgs.map((row) => row.trim()).filter((row) => row !== '');
const thread = childProcess.spawn(this.config.cli, spawnArgs, opts);
process.on('exit', () => { process.on('exit', () => {
if (thread) {
try { try {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('Main thread exiting, cleaning up running CLI'); console.log('Main thread exiting, cleaning up running CLI');
@ -291,8 +290,15 @@ class CLI {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(err); 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 !== '');
thread = childProcess.spawn(this.config.cli, spawnArgs, opts);
thread.stdout.on('data', (data: string) => { thread.stdout.on('data', (data: string) => {
errorLogFull.push(data.toString()); errorLogFull.push(data.toString());
this.parseOutput(data); this.parseOutput(data);
@ -328,6 +334,8 @@ class CLI {
} }
}); });
thread = undefined;
if (!this.config.logFullCliOutput) { if (!this.config.logFullCliOutput) {
this.config.jobLog(errorLogFull.slice(-1000).join('')); this.config.jobLog(errorLogFull.slice(-1000).join(''));
} }

Loading…
Cancel
Save