forked from Shared/esg
Add health check and retry logic and circuit breaker
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import {
|
||||
DiskHealthIndicator,
|
||||
HealthCheck,
|
||||
HealthCheckService,
|
||||
MemoryHealthIndicator,
|
||||
MongooseHealthIndicator,
|
||||
} from '@nestjs/terminus';
|
||||
import { HealthService } from './health.service';
|
||||
|
||||
@Controller('health')
|
||||
export class HealthController {
|
||||
constructor(
|
||||
private readonly health: HealthCheckService,
|
||||
private readonly mongoose: MongooseHealthIndicator,
|
||||
private readonly memory: MemoryHealthIndicator,
|
||||
private readonly disk: DiskHealthIndicator,
|
||||
private readonly healthService: HealthService,
|
||||
) {}
|
||||
|
||||
@Get('live')
|
||||
@HealthCheck({ swaggerDocumentation: false })
|
||||
liveness() {
|
||||
return this.health.check([]);
|
||||
}
|
||||
|
||||
@Get('ready')
|
||||
@HealthCheck({ swaggerDocumentation: false })
|
||||
readiness() {
|
||||
return this.health.check([
|
||||
() => this.mongoose.pingCheck('mongodb', { timeout: 1000 }),
|
||||
() => this.memory.checkHeap('memory_heap', this.healthService.heapThresholdBytes()),
|
||||
() =>
|
||||
this.disk.checkStorage('disk', {
|
||||
path: this.healthService.diskPath(),
|
||||
thresholdPercent: this.healthService.diskThresholdPercent(),
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user