mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-16 06:01:56 +00:00
Refactor ProcessManagerService to be stateless
This commit is contained in:
parent
21043ee74e
commit
ffcc608a97
@ -1,3 +1,4 @@
|
|||||||
export class ProcessCommand {
|
export class ProcessCommand {
|
||||||
command: string;
|
command: string;
|
||||||
|
process_name: string;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
|||||||
|
|
||||||
import { WebSocketService } from './websocket.service';
|
import { WebSocketService } from './websocket.service';
|
||||||
import { ProcessCommand } from './processcommand';
|
import { ProcessCommand } from './processcommand';
|
||||||
|
import { filter } from 'rxjs/operators';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -11,31 +12,31 @@ export class ProcessManagerService {
|
|||||||
|
|
||||||
constructor(private webSocketService: WebSocketService) {}
|
constructor(private webSocketService: WebSocketService) {}
|
||||||
|
|
||||||
init(process_name: string) {
|
init() {
|
||||||
this.process_name = process_name;
|
|
||||||
this.webSocketService.connect();
|
this.webSocketService.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeCallback(callback: (event: any) => void) {
|
subscribeCallback(process_name: string, callback: (event: any) => void) {
|
||||||
this.webSocketService.observeKey<ProcessCommand>(this.key).subscribe(callback);
|
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) {
|
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) {
|
startProcess(process_name: string, callback?: (event: any) => void) {
|
||||||
this.sendCommand('start', callback);
|
this.sendCommand('start', process_name, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
stopProcess(callback?: (event: any) => void) {
|
stopProcess(process_name: string, callback?: (event: any) => void) {
|
||||||
this.sendCommand('stop', callback);
|
this.sendCommand('stop', process_name, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
restartProcess(callback?: (event: any) => void) {
|
restartProcess(process_name: string, callback?: (event: any) => void) {
|
||||||
this.sendCommand('restart', callback);
|
this.sendCommand('restart', process_name, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user