Add health check and retry logic and circuit breaker

This commit is contained in:
SepehrYahyaee
2026-09-28 17:01:53 +03:30
parent 22371f4a03
commit 03fa5e0f20
67 changed files with 3101 additions and 410 deletions
+40
View File
@@ -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(),
}),
]);
}
}