Implement healthcheck service
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
30
projects/common/src/fm/services/healthcheck.service.ts
Normal file
30
projects/common/src/fm/services/healthcheck.service.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable,BehaviorSubject,of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { HttpClient, HttpXhrBackend } from "@angular/common/http";
|
||||
import { AppConfig } from "../shared/app.config";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class HealthCheckService {
|
||||
private httpClient: HttpClient;
|
||||
|
||||
constructor(xhrBackend: HttpXhrBackend, public appConfig: AppConfig) {
|
||||
this.httpClient = new HttpClient(xhrBackend);
|
||||
}
|
||||
|
||||
ApiEndpoint() {
|
||||
return this.appConfig.getConfig("apiEndPoint");
|
||||
}
|
||||
|
||||
check(interval:number): Observable<boolean> {
|
||||
let retval = new BehaviorSubject<boolean>(false);
|
||||
setInterval(() => {
|
||||
this.httpClient.get(`${this.ApiEndpoint()}/api/v1/healthcheck`).pipe(map(() => true),catchError((error) => of(false))).toPromise().then((status) => {
|
||||
retval.next(status);
|
||||
});
|
||||
},interval);
|
||||
return retval;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user