Refactor thread kill

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

@ -274,13 +274,12 @@ class CLI {
const errorLogFull: string[] = [];
this.config.jobLog(`Running ${this.config.cli} ${this.config.spawnArgs.join(' ')}`);
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);
// 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');
@ -291,8 +290,15 @@ class CLI {
// 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 !== '');
thread = childProcess.spawn(this.config.cli, spawnArgs, opts);
thread.stdout.on('data', (data: string) => {
errorLogFull.push(data.toString());
this.parseOutput(data);
@ -328,6 +334,8 @@ class CLI {
}
});
thread = undefined;
if (!this.config.logFullCliOutput) {
this.config.jobLog(errorLogFull.slice(-1000).join(''));
}

Loading…
Cancel
Save