Merge pull request #14 from avatao-content/error_handling

Implement robust error handling
This commit is contained in:
Bokros Bálint 2018-03-07 17:16:19 +01:00 committed by GitHub
commit 10cf9907d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View File

@ -1,4 +1,5 @@
export class ProcessCommand {
command: string;
process_name: string;
error?: string;
}

View File

@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { ProcessCommand } from './processcommand';
import { filter } from 'rxjs/operators';
import { WSMessage } from './wsmessage';
@Injectable()
@ -16,9 +17,17 @@ export class ProcessManagerService {
this.webSocketService.connect();
}
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);
subscribeCallback(process_name: string, callback: (event: WSMessage<ProcessCommand>) => void) {
this.observeProcessMessage(process_name).subscribe(callback);
}
subscribeErrorCallback(process_name: string, callback: (event: WSMessage<ProcessCommand>) => void) {
this.observeProcessMessage(process_name).pipe(filter(message => 'error' in message.data)).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) {

View File

@ -27,7 +27,9 @@
[class.btn-success]="deployButtonState === 'DEPLOYED'"
[class.btn-info]="deployButtonState === 'DEPLOYING'"
[class.disabled]="deployButtonState === 'DEPLOYING' || deployButtonState === 'DEPLOYED'"
[class.btn-danger]="deployButtonState === 'FAILED'"
><span *ngIf="deployButtonState === 'TODEPLOY'">Deploy</span>
<span *ngIf="deployButtonState === 'DEPLOYED'">Deploy</span>
<span *ngIf="deployButtonState === 'DEPLOYING'"><div class="loader"></div>Reloading app...</span></button>
<span *ngIf="deployButtonState === 'DEPLOYING'"><div class="loader"></div>Reloading app...</span>
<span *ngIf="deployButtonState === 'FAILED'">Deployment failed</span></button>
</div>

View File

@ -51,6 +51,7 @@ export class WebideComponent implements OnInit {
this.requestCode();
this.processManagerService.init();
this.processManagerService.subscribeCallback('login', (event) => { this.setDeployButtonState('DEPLOYED'); });
this.processManagerService.subscribeErrorCallback('login', (event) => { this.setDeployButtonState('FAILED'); });
this.resetAutoSaveCountdown();
}