diff --git a/app/package-lock.json b/app/package-lock.json index fd00b40..86781b5 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,6 +1,6 @@ { "name": "scheduler", - "version": "0.0.34", + "version": "0.0.35", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/app/package.json b/app/package.json index ec9bedb..a12da60 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "scheduler", - "version": "0.0.34", + "version": "0.0.35", "description": "Open source application for scheduling tasks (processes)", "main": "dist/main", "authors": "michael sorensen", diff --git a/app/src/main/scheduleRunner.ts b/app/src/main/scheduleRunner.ts index 7f68c31..f3f5bd7 100644 --- a/app/src/main/scheduleRunner.ts +++ b/app/src/main/scheduleRunner.ts @@ -6,6 +6,7 @@ import { killProcess, spacesNotInQuotesRegex } from "./helpers"; import { normalize } from "path"; import Queue from "queue"; import { cpus } from "os"; +import { WriteStream } from "fs"; /** * this singleton is responsible for running the commands at the appropriate time @@ -171,6 +172,28 @@ export class ScheduleRunner { }); } + private handleTaskError(task:Task, err:Error, loggerWriteStream:WriteStream){ + try{ + console.log(err); + if(loggerWriteStream.writable){ + loggerWriteStream.write(err.name + '\n'); + loggerWriteStream.write(err.message + '\n'); + if(err.stack) loggerWriteStream.write(err.stack + '\n'); + } + + const __task: Task = { + ...task, + status: "failed", + }; + this.taskFailedListeners.forEach((cb) => { + cb(__task); + }); + this.scheduleController.updateTask(__task); + }catch(e){ + console.log('unable to handle process error'); + console.log(e); + } + } /** * this is the main start task function * @param task @@ -199,42 +222,35 @@ export class ScheduleRunner { const _process = spawn(command, commandArgs, task.spawnOptions) const loggerWriteStream = taskLogger(task, _process); - _process.on('error', (err)=>{ - loggerWriteStream.write(err.name + '\n'); - loggerWriteStream.write(err.message + '\n'); - if(err.stack) loggerWriteStream.write(err.stack + '\n'); - const __task: Task = { - ...task, - status: "failed", - }; - this.taskFailedListeners.forEach((cb) => { - cb(__task); - }); - this.scheduleController.updateTask(__task); - }) + _process.on('error', (err)=>this.handleTaskError(task, err, loggerWriteStream)) _process.on("exit", (code) => { - loggerWriteStream.write(`Process Completed with code: ${code}`); - loggerWriteStream.close(); - if (code === 0) { - const __task: Task = { - ...task, - status: "waiting", - }; - this.taskWaitingListeners.forEach((cb) => { - cb(__task); - }); - this.scheduleController.updateTask(__task); - }else { - const __task: Task = { - ...task, - status: "failed", - }; - this.taskWaitingListeners.forEach((cb) => { - cb(__task); - }); - this.scheduleController.updateTask(__task); + try{ + + if(loggerWriteStream.writable) loggerWriteStream.write(`Process Completed with code: ${code}`); + if (code === 0) { + const __task: Task = { + ...task, + status: "waiting", + }; + this.taskWaitingListeners.forEach((cb) => { + cb(__task); + }); + this.scheduleController.updateTask(__task); + }else { + const __task: Task = { + ...task, + status: "failed", + }; + this.taskWaitingListeners.forEach((cb) => { + cb(__task); + }); + this.scheduleController.updateTask(__task); + } + }catch(err){ + this.handleTaskError(task, err, loggerWriteStream) } + }); this.scheduleController.startTask({ ...task, diff --git a/app/src/renderer/src/app/components/task-logs/task-logs.component.ts b/app/src/renderer/src/app/components/task-logs/task-logs.component.ts index 5ecd433..e14a8e0 100644 --- a/app/src/renderer/src/app/components/task-logs/task-logs.component.ts +++ b/app/src/renderer/src/app/components/task-logs/task-logs.component.ts @@ -45,7 +45,7 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{ await new Promise((resolve, reject)=>{ this.term.write('\u001B[2J', ()=>resolve(true)); }) - this.term.write(text); + this.term.write(text.replace(/\r(?!\n)/g, '\r\n')); } handleLogFileUpdateEvent(){ @@ -68,7 +68,14 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{ ngAfterViewInit(): void { - this.term = new Terminal(); + this.term = new Terminal({ + disableStdin: true, + convertEol: true, + windowsPty: { + backend: 'conpty', + buildNumber: 19045, + }, + }); this.term.open(this.xtermContainer.nativeElement); } } diff --git a/app/test/test.js b/app/test/test.js new file mode 100644 index 0000000..b59262c --- /dev/null +++ b/app/test/test.js @@ -0,0 +1,7 @@ +let count = 1; + +const myInterval = setInterval(()=>{ + if(count > 10) return clearInterval(myInterval); + console.log(count); + count++; +}, 1000) \ No newline at end of file