mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 22:01:11 +10:00
@ -1,31 +1,30 @@
|
||||
import { InjectKysely } from 'nestjs-kysely';
|
||||
import {
|
||||
HealthCheckError,
|
||||
HealthIndicator,
|
||||
HealthIndicatorResult,
|
||||
HealthIndicatorService,
|
||||
} from '@nestjs/terminus';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { sql } from 'kysely';
|
||||
import { KyselyDB } from '@docmost/db/types/kysely.types';
|
||||
|
||||
@Injectable()
|
||||
export class PostgresHealthIndicator extends HealthIndicator {
|
||||
export class PostgresHealthIndicator {
|
||||
private readonly logger = new Logger(PostgresHealthIndicator.name);
|
||||
|
||||
constructor(@InjectKysely() private readonly db: KyselyDB) {
|
||||
super();
|
||||
}
|
||||
constructor(
|
||||
private readonly healthIndicatorService: HealthIndicatorService,
|
||||
@InjectKysely() private readonly db: KyselyDB,
|
||||
) {}
|
||||
|
||||
async pingCheck(key: string): Promise<HealthIndicatorResult> {
|
||||
const indicator = this.healthIndicatorService.check(key);
|
||||
|
||||
try {
|
||||
await sql`SELECT 1=1`.execute(this.db);
|
||||
return this.getStatus(key, true);
|
||||
return indicator.up();
|
||||
} catch (e) {
|
||||
this.logger.error(JSON.stringify(e));
|
||||
throw new HealthCheckError(
|
||||
`${key} is not available`,
|
||||
this.getStatus(key, false),
|
||||
);
|
||||
return indicator.down(`${key} is not available`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,23 @@
|
||||
import {
|
||||
HealthCheckError,
|
||||
HealthIndicator,
|
||||
HealthIndicatorResult,
|
||||
HealthIndicatorService,
|
||||
} from '@nestjs/terminus';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { EnvironmentService } from '../environment/environment.service';
|
||||
import { Redis } from 'ioredis';
|
||||
|
||||
@Injectable()
|
||||
export class RedisHealthIndicator extends HealthIndicator {
|
||||
export class RedisHealthIndicator {
|
||||
private readonly logger = new Logger(RedisHealthIndicator.name);
|
||||
|
||||
constructor(private environmentService: EnvironmentService) {
|
||||
super();
|
||||
}
|
||||
constructor(
|
||||
private readonly healthIndicatorService: HealthIndicatorService,
|
||||
private environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
async pingCheck(key: string): Promise<HealthIndicatorResult> {
|
||||
const indicator = this.healthIndicatorService.check(key);
|
||||
|
||||
try {
|
||||
const redis = new Redis(this.environmentService.getRedisUrl(), {
|
||||
maxRetriesPerRequest: 15,
|
||||
@ -23,13 +25,10 @@ export class RedisHealthIndicator extends HealthIndicator {
|
||||
|
||||
await redis.ping();
|
||||
redis.disconnect();
|
||||
return this.getStatus(key, true);
|
||||
return indicator.up();
|
||||
} catch (e) {
|
||||
this.logger.error(e);
|
||||
throw new HealthCheckError(
|
||||
`${key} is not available`,
|
||||
this.getStatus(key, false),
|
||||
);
|
||||
return indicator.down(`${key} is not available`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user