feat(center): enhance health check with DB readiness

This commit is contained in:
nav
2026-05-12 08:58:44 +00:00
parent 7270256587
commit 2e2e217b5f
2 changed files with 20 additions and 4 deletions

View File

@@ -1,9 +1,25 @@
import { Controller, Get } from '@nestjs/common'; import { Controller, Get, ServiceUnavailableException } from '@nestjs/common';
import { DataSource } from 'typeorm';
@Controller('healthz') @Controller('healthz')
export class HealthController { export class HealthController {
constructor(private readonly dataSource: DataSource) {}
@Get() @Get()
get() { async get() {
return { ok: true, service: 'center' }; try {
await this.dataSource.query('SELECT 1');
return {
ok: true,
service: 'center',
database: 'ready',
};
} catch {
throw new ServiceUnavailableException({
ok: false,
service: 'center',
database: 'not_ready',
});
}
} }
} }

View File

@@ -31,7 +31,7 @@
### 1.3 Center 运维能力 ### 1.3 Center 运维能力
- [x] 审计日志auth/node 关键操作) - [x] 审计日志auth/node 关键操作)
- [ ] 健康检查深化DB ready - [x] 健康检查深化DB ready
- [x] 配置校验(启动时必填项检查) - [x] 配置校验(启动时必填项检查)
--- ---