|
| 1 | +import { Injectable, OnModuleInit } from '@nestjs/common'; |
| 2 | +import { BaseEventHandler } from '../base-event.handler'; |
| 3 | +import { KafkaHandlerRegistry } from '../kafka-handler.registry'; |
| 4 | +import { LoggerService } from '../../global/logger.service'; |
| 5 | + |
| 6 | +@Injectable() |
| 7 | +export class SubmissionScanCompleteHandler |
| 8 | + extends BaseEventHandler |
| 9 | + implements OnModuleInit |
| 10 | +{ |
| 11 | + private readonly topic = 'submission.scan.complete'; |
| 12 | + |
| 13 | + constructor(private readonly handlerRegistry: KafkaHandlerRegistry) { |
| 14 | + super(LoggerService.forRoot('SubmissionScanCompleteHandler')); |
| 15 | + } |
| 16 | + |
| 17 | + onModuleInit() { |
| 18 | + this.handlerRegistry.registerHandler(this.topic, this); |
| 19 | + this.logger.log(`Registered handler for topic: ${this.topic}`); |
| 20 | + } |
| 21 | + |
| 22 | + getTopic(): string { |
| 23 | + return this.topic; |
| 24 | + } |
| 25 | + |
| 26 | + async handle(message: any): Promise<void> { |
| 27 | + try { |
| 28 | + this.logger.log({ |
| 29 | + message: 'Processing Submission Scan Complete event', |
| 30 | + topic: this.topic, |
| 31 | + payload: message, |
| 32 | + }); |
| 33 | + |
| 34 | + if (!this.validateMessage(message)) { |
| 35 | + this.logger.warn('Invalid message received'); |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + this.logger.log('=== Submission Scan Complete Event ==='); |
| 40 | + this.logger.log('Topic:', this.topic); |
| 41 | + this.logger.log('Payload:', JSON.stringify(message, null, 2)); |
| 42 | + this.logger.log('=============================='); |
| 43 | + |
| 44 | + await Promise.resolve(); // Add await to satisfy linter |
| 45 | + |
| 46 | + this.logger.log('Submission Scan Complete event processed successfully'); |
| 47 | + } catch (error) { |
| 48 | + this.logger.error( |
| 49 | + 'Error processing Submission Scan Complete event', |
| 50 | + error, |
| 51 | + ); |
| 52 | + throw error; |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments