mirror of
https://github.com/docmost/docmost.git
synced 2026-08-28 17:27:06 +08:00
35 lines
958 B
TypeScript
35 lines
958 B
TypeScript
import {
|
|
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 {
|
|
private readonly logger = new Logger(RedisHealthIndicator.name);
|
|
|
|
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,
|
|
});
|
|
|
|
await redis.ping();
|
|
redis.disconnect();
|
|
return indicator.up();
|
|
} catch (e) {
|
|
this.logger.error(e);
|
|
return indicator.down(`${key} is not available`);
|
|
}
|
|
}
|
|
}
|