mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
Merge branch 'kill_thread' of https://github.com/HaveAGitGat/Tdarr_Plugins into kill_thread
This commit is contained in:
commit
8ca3dde779
1 changed files with 41 additions and 9 deletions
|
|
@ -224,6 +224,29 @@ var CLI = /** @class */ (function () {
|
|||
}
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
|
||||
this.killThread = function (thread) {
|
||||
var killArray = [
|
||||
'SIGKILL',
|
||||
'SIGHUP',
|
||||
'SIGTERM',
|
||||
'SIGINT',
|
||||
];
|
||||
try {
|
||||
thread.kill();
|
||||
}
|
||||
catch (err) {
|
||||
// err
|
||||
}
|
||||
killArray.forEach(function (com) {
|
||||
try {
|
||||
thread.kill(com);
|
||||
}
|
||||
catch (err) {
|
||||
// err
|
||||
}
|
||||
});
|
||||
};
|
||||
this.runCli = function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var childProcess, errorLogFull, cliExitCode;
|
||||
var _this = this;
|
||||
|
|
@ -232,26 +255,35 @@ var CLI = /** @class */ (function () {
|
|||
case 0:
|
||||
childProcess = require('child_process');
|
||||
errorLogFull = [];
|
||||
// eslint-disable-next-line no-console
|
||||
this.config.jobLog("Running ".concat(this.config.cli, " ").concat(this.config.spawnArgs.join(' ')));
|
||||
return [4 /*yield*/, new Promise(function (resolve) {
|
||||
try {
|
||||
var opts = _this.config.spawnOpts || {};
|
||||
var spawnArgs = _this.config.spawnArgs.map(function (row) { return row.trim(); }).filter(function (row) { return row !== ''; });
|
||||
var thread = childProcess.spawn(_this.config.cli, spawnArgs, opts);
|
||||
thread.stdout.on('data', function (data) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log(data.toString());
|
||||
var thread_1 = childProcess.spawn(_this.config.cli, spawnArgs, opts);
|
||||
process.on('exit', function () {
|
||||
try {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Main thread exiting, cleaning up running CLI');
|
||||
_this.killThread(thread_1);
|
||||
}
|
||||
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_1.stdout.on('data', function (data) {
|
||||
errorLogFull.push(data.toString());
|
||||
_this.parseOutput(data);
|
||||
});
|
||||
thread.stderr.on('data', function (data) {
|
||||
thread_1.stderr.on('data', function (data) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log(data.toString());
|
||||
errorLogFull.push(data.toString());
|
||||
_this.parseOutput(data);
|
||||
});
|
||||
thread.on('error', function () {
|
||||
thread_1.on('error', function () {
|
||||
// catches execution error (bad file)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(1, "Error executing binary: ".concat(_this.config.cli));
|
||||
|
|
@ -259,7 +291,7 @@ var CLI = /** @class */ (function () {
|
|||
});
|
||||
// thread.stdout.pipe(process.stdout);
|
||||
// thread.stderr.pipe(process.stderr);
|
||||
thread.on('close', function (code) {
|
||||
thread_1.on('close', function (code) {
|
||||
if (code !== 0) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(code, 'CLI error');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue