forked from Sunbird-Obsrv/obsrv-api-service
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9fb75f6
commit 5be2f0d
Showing
5 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { AxiosInstance } from "axios"; | ||
import { NextFunction, Request, Response } from "express"; | ||
import _ from "lodash"; | ||
import { ResponseHandler } from "../helpers/ResponseHandler"; | ||
import { ErrorResponseHandler } from "../helpers/ErrorResponseHandler"; | ||
import { IConnector } from "../models/DatasetModels"; | ||
import { DbConnector } from "../connectors/DbConnector"; | ||
import { KafkaConnector } from "../connectors/KafkaConnector"; | ||
|
||
|
||
|
||
|
||
export class HealthService { | ||
private dbConnector: DbConnector; | ||
private kafkaConnector: KafkaConnector; | ||
private httpDruidConnector: AxiosInstance; | ||
private errorHandler: ErrorResponseHandler; | ||
constructor(dbConnector: DbConnector, kafkaConnector: KafkaConnector, httpDruidConnector: IConnector) { | ||
this.errorHandler = new ErrorResponseHandler("HealthService"); | ||
this.httpDruidConnector = httpDruidConnector.connect() | ||
this.dbConnector = dbConnector; | ||
this.kafkaConnector = kafkaConnector; | ||
} | ||
|
||
checkHealth(req: Request, res: Response, next: NextFunction) { | ||
Promise.all([this.checkDruidHealth(), this.checkKafkaHealth(), this.checkPostgresHealth()]) | ||
.then(() => { | ||
ResponseHandler.successResponse(req, res, { status: 200, data: {} }) | ||
}).catch(error => { | ||
this.errorHandler.handleError(req, res, next, error) | ||
}) | ||
} | ||
|
||
private async checkDruidHealth() { | ||
await this.httpDruidConnector.get("/status/health") | ||
} | ||
|
||
private async checkKafkaHealth() { | ||
await this.kafkaConnector.connect() | ||
} | ||
|
||
private async checkPostgresHealth() { | ||
await this.dbConnector.health() | ||
} | ||
|
||
} |