feat(center): enhance health check with DB readiness
This commit is contained in:
@@ -1,9 +1,25 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Controller, Get, ServiceUnavailableException } from '@nestjs/common';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
@Controller('healthz')
|
||||
export class HealthController {
|
||||
constructor(private readonly dataSource: DataSource) {}
|
||||
|
||||
@Get()
|
||||
get() {
|
||||
return { ok: true, service: 'center' };
|
||||
async get() {
|
||||
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',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user