2020-09-09 02:59:01 +08:00
|
|
|
import { HttpProvider, HttpResponse, Heart, HttpProviderOptions } from "../http"
|
2020-08-31 23:29:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the heartbeat.
|
|
|
|
*/
|
|
|
|
export class HealthHttpProvider extends HttpProvider {
|
|
|
|
public constructor(options: HttpProviderOptions, private readonly heart: Heart) {
|
|
|
|
super(options)
|
|
|
|
}
|
|
|
|
|
2020-09-09 02:59:01 +08:00
|
|
|
public async handleRequest(): Promise<HttpResponse> {
|
|
|
|
return {
|
2020-08-31 23:29:12 +08:00
|
|
|
cache: false,
|
|
|
|
mime: "application/json",
|
|
|
|
content: {
|
|
|
|
status: this.heart.alive() ? "alive" : "expired",
|
|
|
|
lastHeartbeat: this.heart.lastHeartbeat,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|