28 lines
686 B
TypeScript
28 lines
686 B
TypeScript
import { Controller, Get } from '@nestjs/common';
|
|
import { ApiError } from '../common/filters/api-error';
|
|
import { PrismaService } from '../db/prisma.service';
|
|
import { isDraining } from './shutdown';
|
|
|
|
@Controller('health')
|
|
export class HealthController {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
@Get('live')
|
|
live(): { status: 'ok' } {
|
|
return { status: 'ok' };
|
|
}
|
|
|
|
@Get('ready')
|
|
async ready(): Promise<{ status: 'ok' }> {
|
|
if (isDraining()) {
|
|
throw new ApiError('unavailable', 'shutting down');
|
|
}
|
|
try {
|
|
await this.prisma.$queryRaw`SELECT 1`;
|
|
} catch {
|
|
throw new ApiError('unavailable', 'database unavailable');
|
|
}
|
|
return { status: 'ok' };
|
|
}
|
|
}
|