Skip to content

Commit

Permalink
Merge pull request #124 from swordensen/development
Browse files Browse the repository at this point in the history
v0.0.35
  • Loading branch information
swordensen authored Feb 8, 2024
2 parents e3c1248 + 936be78 commit a87347a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
82 changes: 49 additions & 33 deletions app/src/main/scheduleRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -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);
}
}
7 changes: 7 additions & 0 deletions app/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let count = 1;

const myInterval = setInterval(()=>{
if(count > 10) return clearInterval(myInterval);
console.log(count);
count++;
}, 1000)

0 comments on commit a87347a

Please sign in to comment.