mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2025-12-31 08:42:40 +00:00
refactor to ddh, first commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export interface ICheckRepository {
|
||||
healthCheck(): Promise<boolean>;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
HealthCheckError,
|
||||
HealthIndicator,
|
||||
HealthIndicatorResult,
|
||||
} from '@nestjs/terminus';
|
||||
import { ICheckRepository } from '../interfaces/check-repository.interface';
|
||||
import { AdRepository } from '../../../ad/adapters/secondaries/ad.repository';
|
||||
|
||||
@Injectable()
|
||||
export class RepositoriesHealthIndicatorUseCase extends HealthIndicator {
|
||||
private checkRepositories: ICheckRepository[];
|
||||
constructor(private readonly adRepository: AdRepository) {
|
||||
super();
|
||||
this.checkRepositories = [adRepository];
|
||||
}
|
||||
isHealthy = async (key: string): Promise<HealthIndicatorResult> => {
|
||||
try {
|
||||
await Promise.all(
|
||||
this.checkRepositories.map(
|
||||
async (checkRepository: ICheckRepository) => {
|
||||
await checkRepository.healthCheck();
|
||||
},
|
||||
),
|
||||
);
|
||||
return this.getStatus(key, true);
|
||||
} catch (e: any) {
|
||||
throw new HealthCheckError('Repository', {
|
||||
repository: e.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user