Update services according to the new API

This commit is contained in:
R. Richard 2019-08-07 10:28:48 +02:00
parent a254e27fbf
commit 6b25416973
6 changed files with 28 additions and 31 deletions

View File

@ -1,7 +1,9 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export class FSMUpdate {
import { WebSocketMessage } from './websocket-message';
export interface FSMUpdate extends WebSocketMessage {
current_state: string;
valid_transitions: object;
}

View File

@ -1,10 +1,10 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
import { CommandMessage } from './command-message';
import { LogMessage } from './log-message';
import { WebSocketMessage } from './websocket-message';
export interface ProcessCommand extends CommandMessage, LogMessage {
process_name: string;
export interface ProcessCommand extends WebSocketMessage, LogMessage {
name: string;
error?: string;
}

View File

@ -1,7 +1,7 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
import { CommandMessage } from './command-message';
import { LogMessage } from './log-message';
import { WebSocketMessage } from './websocket-message';
export interface ProcessLogCommand extends CommandMessage, LogMessage {}
export interface ProcessLogCommand extends WebSocketMessage, LogMessage {}

View File

@ -14,9 +14,9 @@ export class FSMUpdateService {
constructor(private websocketService: WebSocketService) {}
public init(): void {
this.websocketService.observeKey<FSMUpdate>('FSMUpdate').subscribe((event) => {
this.current_state = event.data.current_state;
this.valid_transitions = event.data.valid_transitions;
this.websocketService.observeKey<FSMUpdate>('fsm.announce').subscribe((event) => {
this.current_state = event.current_state;
this.valid_transitions = event.valid_transitions;
});
}

View File

@ -3,25 +3,20 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { LogMessage } from '../message-types/log-message';
import { ProcessLogCommand } from '../message-types/process-log-command';
import { config } from '../config';
import { BehaviorSubject } from 'rxjs';
import { LogMessage } from '../message-types/log-message';
import { CommandMessage } from '../message-types/command-message';
@Injectable()
export class ProcessLogService {
newLogs = new BehaviorSubject<LogMessage>(config.console.defaultLogs);
showLiveLogs = config.console.showLiveLogs;
command_handlers = {
'new_log': this.newLogsHandler.bind(this)
};
constructor(private webSocketService: WebSocketService) {
this.webSocketService.connect();
this.webSocketService.observeKey<CommandMessage>('processlog').subscribe(
(event) => this.command_handlers[event.data.command](event.data)
this.webSocketService.observeKey<ProcessLogCommand>('log.new').subscribe(
(event) => this.newLogsHandler(event)
);
}

View File

@ -6,12 +6,9 @@ import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { ProcessCommand } from '../message-types/process-command';
import { filter } from 'rxjs/operators';
import { WebSocketMessage } from '../message-types/websocket-message';
@Injectable()
export class ProcessManagerService {
key = 'processmanager';
process_name: string;
constructor(private webSocketService: WebSocketService) {}
@ -20,25 +17,21 @@ export class ProcessManagerService {
this.webSocketService.connect();
}
subscribeCallback(process_name: string, callback: (event: WebSocketMessage<ProcessCommand>) => void) {
subscribeCallback(process_name: string, callback: (event: ProcessCommand) => void) {
this.observeProcessMessage(process_name).subscribe(callback);
}
subscribeSuccessCallback(process_name: string, callback: (event: WebSocketMessage<ProcessCommand>) => void) {
this.observeProcessMessage(process_name).pipe(filter(message => !('error' in message.data))).subscribe(callback);
subscribeSuccessCallback(process_name: string, callback: (event: ProcessCommand) => void) {
this.observeProcessMessage(process_name).pipe(filter(message => !('error' in message))).subscribe(callback);
}
subscribeErrorCallback(process_name: string, callback: (event: WebSocketMessage<ProcessCommand>) => void) {
this.observeProcessMessage(process_name).pipe(filter(message => 'error' in message.data)).subscribe(callback);
subscribeErrorCallback(process_name: string, callback: (event: ProcessCommand) => void) {
this.observeProcessMessage(process_name).pipe(filter(message => 'error' in message)).subscribe(callback);
}
observeProcessMessage(process_name: string) {
return this.webSocketService.observeKey<ProcessCommand>(this.key)
.pipe(filter(message => message.data.process_name === process_name));
}
sendCommand(command: string, process_name: string) {
this.webSocketService.send(this.key, {'command': command, 'process_name': process_name});
return this.webSocketService.observeKey<ProcessCommand>('process')
.pipe(filter(message => message.name === process_name));
}
startProcess(process_name: string) {
@ -52,4 +45,11 @@ export class ProcessManagerService {
restartProcess(process_name: string) {
this.sendCommand('restart', process_name);
}
sendCommand(command: string, process_name: string) {
this.webSocketService.sendJSON({
'key': 'process.'+command,
'name': process_name
});
}
}