Skip to content

Commit

Permalink
Merge pull request #117 from swordensen/development
Browse files Browse the repository at this point in the history
yuh
  • Loading branch information
swordensen authored Feb 6, 2024
2 parents 541ee4b + 7e5b850 commit 2822ffd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 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.31",
"version": "0.0.32",
"description": "Open source application for scheduling tasks (processes)",
"main": "dist/main",
"authors": "michael sorensen",
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/controllers/schedule.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@ export class ScheduleController {
this._schedule = this.forEachTask(taskGroup => {
if(taskGroup.id === targetTaskGroup.id && taskGroup.type === 'taskGroup'){
console.log("FOUND TASK GROUP TO UPDATE");
const id = uuid()
return {
...taskGroup,
tasks: [
...taskGroup.tasks,
{
...task,
id: uuid(),
id: id,
type: 'task',
pids: [],
logFilePath: resolve(logFolder, `./commands/${task.name}-${task.id}.log`),
logFilePath: resolve(logFolder, `./commands/${task.name}-${id}.log`),
triggers: task.triggers.map((trigger) => {
switch (trigger.type) {
case "CRON":
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/electron-event-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ ipcMain.on(OPEN_TASK_LOG_FILE_EVENT, (event, task: Task) => {
const logFileListeners:{[key:string]: StatWatcher } = {}

ipcMain.on(START_LISTENING_TO_LOG_FILE, (event, task:Task)=>{
console.log('start listening to log file');
if(!task) return;
const logFileController = new LogFileController(task.logFilePath);
if(logFileListeners[task.id]) logFileListeners[task.id].removeAllListeners();
console.log("ESTABLISHING LOG FILE WATCHER");
const watcher = logFileController.onChange((text)=>{
mainWindow.webContents.send(TASK_LOG_FILE_UPDATED, text)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ipcRenderer} from 'electron'
import { Store } from '@ngrx/store';
import { Schedule, Task } from '../../../../../main/types';
import { selectTaskById } from 'src/app/@core/store/selectors/schedule.selectors';
import { first } from 'rxjs/operators';
import { first, take } from 'rxjs/operators';
import { START_LISTENING_TO_LOG_FILE, STOP_LISTENING_TO_LOG_FILE, TASK_LOG_FILE_UPDATED } from '../../../../../event-names';

@Component({
Expand All @@ -20,18 +20,15 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{
@ViewChild("xterm") xtermContainer: ElementRef;


constructor(private router:Router, private route:ActivatedRoute, private store:Store<{schedule:Schedule}>){
constructor( private route:ActivatedRoute, private store:Store<{schedule:Schedule}>){

}

ngOnInit(){

this.route.parent?.parent?.params.subscribe(parentParams => {
console.log(parentParams);
const taskId = parentParams.id
if(!taskId) return;
this.store.select(selectTaskById(taskId)).subscribe(task => {
console.log(task);
this.store.select(selectTaskById(taskId)).pipe(take(1)).subscribe(task => {
if(!task) return;
this.task = task;
this.startListeningToLogFile(task)
Expand All @@ -42,11 +39,18 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{

}

handleLogFileUpdateEvent(){
ipcRenderer.on(TASK_LOG_FILE_UPDATED, (event, text)=>{
console.log("TASK_LOG_FILE_UPDATED");
this.term.write(text);


async onTaskFileUpdated(event:Electron.IpcRendererEvent, text:string){
console.log("TASK_LOG_FILE_UPDATED");
await new Promise((resolve, reject)=>{
this.term.write('\u001B[2J', ()=>resolve(true));
})
this.term.write(text);
}

handleLogFileUpdateEvent(){
ipcRenderer.on(TASK_LOG_FILE_UPDATED, this.onTaskFileUpdated.bind(this))
}

startListeningToLogFile(task:Task){
Expand All @@ -61,12 +65,12 @@ export class TaskLogsComponent implements OnInit, AfterViewInit, OnDestroy{

ngOnDestroy(): void {
this.stopListeningToLogFile();
ipcRenderer.removeListener(TASK_LOG_FILE_UPDATED, this.onTaskFileUpdated.bind(this));
}


ngAfterViewInit(): void {
this.term = new Terminal();
this.term.open(this.xtermContainer.nativeElement);
this.term.writeln("HELLO WORLD!");
}
}

0 comments on commit 2822ffd

Please sign in to comment.