mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-16 03:11:56 +00:00
Refactor ProcessManagerService to be stateless
This commit is contained in:
parent
21043ee74e
commit
ffcc608a97
@ -1,3 +1,4 @@
|
||||
export class ProcessCommand {
|
||||
command: string;
|
||||
process_name: string;
|
||||
}
|
||||
|
@ -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<ProcessCommand>(this.key).subscribe(callback);
|
||||
subscribeCallback(process_name: string, callback: (event: any) => void) {
|
||||
this.webSocketService.observeKey<ProcessCommand>(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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user