mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-12 15:52:32 +10:00
cr - add redis check and logging
This commit is contained in:
@ -5,22 +5,33 @@ import {
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
InternalServerErrorException,
|
||||
Post,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
import { sql } from 'kysely';
|
||||
import { InjectKysely } from 'nestjs-kysely';
|
||||
import { Redis } from 'ioredis';
|
||||
import { EnvironmentService } from '../environment/environment.service';
|
||||
|
||||
@Controller()
|
||||
export class HealthController {
|
||||
constructor(@InjectKysely() private readonly db: KyselyDB) {}
|
||||
constructor(
|
||||
@InjectKysely() private readonly db: KyselyDB,
|
||||
private environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
private readonly logger = new Logger(HealthController.name);
|
||||
|
||||
@Get('health')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async health() {
|
||||
try {
|
||||
const redis = new Redis(this.environmentService.getRedisUrl());
|
||||
|
||||
await sql`SELECT 1=1`.execute(this.db);
|
||||
await redis.ping();
|
||||
} catch (error) {
|
||||
throw new InternalServerErrorException('Health check failed');
|
||||
this.logger.error('Health check failed');
|
||||
throw new InternalServerErrorException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user