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