Implement first version of ProcessManagerService

This commit is contained in:
Kristóf Tóth 2018-02-21 15:00:10 +01:00
parent a2e5dc39a9
commit fefed5b84e
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,3 @@
export class ProcessCommand {
command: string;
}

View File

@ -0,0 +1,41 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { ProcessCommand } from './processcommand';
@Injectable()
export class ProcessManagerService {
anchor = 'anchor_processmanager';
process_name: string;
constructor(private webSocketService: WebSocketService) {}
init(process_name: string) {
this.process_name = process_name;
this.webSocketService.connect();
}
subscribeCallback(callback: (event: any) => void) {
this.webSocketService.observeAnchor<ProcessCommand>(this.anchor).subscribe(callback);
}
sendCommand(command: string, callback?: (event: any) => void) {
if (callback) {
this.subscribeCallback(callback);
}
this.webSocketService.send(this.anchor, {'command': command});
}
startProcess(callback?: (event: any) => void) {
this.sendCommand('start', callback);
}
stopProcess(callback?: (event: any) => void) {
this.sendCommand('stop', callback);
}
restartProcess(callback?: (event: any) => void) {
this.sendCommand('restart', callback);
}
}