app/src/commons/component/service-detail.component.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-18 21:25:47 +09:00
import { Component, Input, Output, EventEmitter } from '@angular/core';
2018-09-09 19:20:21 +09:00
import { Service } from '@overflow/model/discovery';
2018-09-18 21:25:47 +09:00
import { PingResult } from '@overflow/model/ping';
import { ProbeService } from '../service/probe.service';
import { map, catchError, take } from 'rxjs/operators';
import { of } from 'rxjs';
2018-09-09 19:20:21 +09:00
@Component({
selector: 'app-service-detail',
templateUrl: './service-detail.component.html',
styleUrls: ['./service-detail.component.scss'],
})
export class ServiceDetailComponent {
@Input() service: Service;
2018-09-18 21:25:47 +09:00
@Output() ping = new EventEmitter<PingResult>();
2018-09-09 19:20:21 +09:00
constructor(
2018-09-18 21:25:47 +09:00
private probeService: ProbeService
2018-09-09 19:20:21 +09:00
) {
}
2018-09-18 21:25:47 +09:00
doPing() {
const option = {
Retry: 3,
Interval: 1,
Deadline: 1,
};
this.probeService
.call<PingResult>('PingService.PingService', this.service, option)
.pipe(
map((pingResult: PingResult) => {
this.ping.emit(pingResult);
}),
catchError(error => {
console.log(error);
alert('An error has occurred.');
return of();
}),
take(1)
)
.subscribe();
2018-09-13 20:01:01 +09:00
}
2018-09-09 19:20:21 +09:00
}