Skip to content

Commit

Permalink
BC-6338 - WIP add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenWaysDP committed Feb 5, 2024
1 parent 7e4f4cc commit 88f306f
Show file tree
Hide file tree
Showing 6 changed files with 457 additions and 36 deletions.
16 changes: 16 additions & 0 deletions apps/server/src/infra/healthcheck/healthcheck.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DynamicModule, Module, Type } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus';
import { AmqpConsumerHealthIndicator } from './indicators/amqp-consumer.indictor';

@Module({})
export class HealthCheckModule {
static register(controllers?: Type<any>[]): DynamicModule {
return {
module: HealthCheckModule,
imports: [TerminusModule],
providers: [AmqpConsumerHealthIndicator],
exports: [AmqpConsumerHealthIndicator],
controllers,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
import { HealthCheckError, HealthIndicator, HealthIndicatorResult } from '@nestjs/terminus';

export class AmqpConsumerHealthIndicator extends HealthIndicator {
private amqpConnection!: AmqpConnection;

setAmqpConnection(connection: AmqpConnection) {
this.amqpConnection = connection;
}

public isHealthy(key: string): HealthIndicatorResult {
const { consumerTags, channels } = this.amqpConnection;
console.log('CHANNELS', channels);
console.log('CONSUMER_TAGS', consumerTags);

const isHealthy = consumerTags.length > 0;

const result = this.getStatus(key, isHealthy);

if (isHealthy) {
return result;
}
throw new HealthCheckError('Consumer check failed', result);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DynamicModule, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { HealthCheckModule } from '@infra/healthcheck/healthcheck.module';
import { RabbitMQWrapperModule } from '@infra/rabbitmq';
import { S3ClientAdapter, S3ClientModule } from '@infra/s3-client';
import { DynamicModule, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ScheduleModule } from '@nestjs/schedule';
import { createConfigModuleOptions } from '@src/config';
import { Logger, LoggerModule } from '@src/core/logger';
import { PreviewConfig } from './interface/preview-consumer-config';
Expand All @@ -25,6 +27,8 @@ export class PreviewGeneratorConsumerModule {
return {
module: PreviewGeneratorConsumerModule,
imports: [
HealthCheckModule.register(),
ScheduleModule.forRoot(),
LoggerModule,
S3ClientModule.register([storageConfig]),
RabbitMQWrapperModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { RabbitPayload, RabbitRPC } from '@golevelup/nestjs-rabbitmq';
import { AmqpConnection, RabbitPayload, RabbitRPC } from '@golevelup/nestjs-rabbitmq';
import { AmqpConsumerHealthIndicator } from '@infra/healthcheck/indicators/amqp-consumer.indictor';
import { FilesPreviewEvents, FilesPreviewExchange } from '@infra/rabbitmq';
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { Logger } from '@src/core/logger';
import { PreviewFileOptions } from './interface';
import { PreviewActionsLoggable } from './loggable/preview-actions.loggable';
import { PreviewGeneratorService } from './preview-generator.service';

@Injectable()
export class PreviewGeneratorConsumer {
constructor(private readonly previewGeneratorService: PreviewGeneratorService, private logger: Logger) {
constructor(
private readonly previewGeneratorService: PreviewGeneratorService,
private logger: Logger,
private amqpConnection: AmqpConnection,
private health: AmqpConsumerHealthIndicator
) {
this.logger.setContext(PreviewGeneratorConsumer.name);
health.setAmqpConnection(amqpConnection);
}

@Cron('5 * * * * *')
healty() {
console.log(this.health.isHealthy('preview-generator-consumer'));
}

@RabbitRPC({
Expand Down
Loading

0 comments on commit 88f306f

Please sign in to comment.