From ffcc608a979616e6d73427063640f99cc0e2c83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Feb 2018 15:55:23 +0100 Subject: [PATCH] Refactor ProcessManagerService to be stateless --- src/app/services/processcommand.ts | 1 + src/app/services/processmanager.service.ts | 27 +++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/app/services/processcommand.ts b/src/app/services/processcommand.ts index 9b6d711..f275533 100644 --- a/src/app/services/processcommand.ts +++ b/src/app/services/processcommand.ts @@ -1,3 +1,4 @@ export class ProcessCommand { command: string; + process_name: string; } diff --git a/src/app/services/processmanager.service.ts b/src/app/services/processmanager.service.ts index e041436..677119f 100644 --- a/src/app/services/processmanager.service.ts +++ b/src/app/services/processmanager.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { WebSocketService } from './websocket.service'; import { ProcessCommand } from './processcommand'; +import { filter } from 'rxjs/operators'; @Injectable() @@ -11,31 +12,31 @@ export class ProcessManagerService { constructor(private webSocketService: WebSocketService) {} - init(process_name: string) { - this.process_name = process_name; + init() { this.webSocketService.connect(); } - subscribeCallback(callback: (event: any) => void) { - this.webSocketService.observeKey(this.key).subscribe(callback); + subscribeCallback(process_name: string, callback: (event: any) => void) { + this.webSocketService.observeKey(this.key) + .pipe(filter(message => message.data.process_name === process_name)).subscribe(callback); } - sendCommand(command: string, callback?: (event: any) => void) { + sendCommand(command: string, process_name: string, callback?: (event: any) => void) { if (callback) { - this.subscribeCallback(callback); + this.subscribeCallback(process_name, callback); } - this.webSocketService.send(this.key, {'command': command}); + this.webSocketService.send(this.key, {'command': command, 'process_name': process_name}); } - startProcess(callback?: (event: any) => void) { - this.sendCommand('start', callback); + startProcess(process_name: string, callback?: (event: any) => void) { + this.sendCommand('start', process_name, callback); } - stopProcess(callback?: (event: any) => void) { - this.sendCommand('stop', callback); + stopProcess(process_name: string, callback?: (event: any) => void) { + this.sendCommand('stop', process_name, callback); } - restartProcess(callback?: (event: any) => void) { - this.sendCommand('restart', callback); + restartProcess(process_name: string, callback?: (event: any) => void) { + this.sendCommand('restart', process_name, callback); } }