feat(pipeline-task): logger.
This commit is contained in:
35
src/pipeline-tasks/pipeline-task.logger.ts
Normal file
35
src/pipeline-tasks/pipeline-task.logger.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
|
||||
import { Injectable, OnModuleDestroy } from '@nestjs/common';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { filter, publish, tap } from 'rxjs/operators';
|
||||
import { PipelineTaskEvent } from './models/pipeline-task-event';
|
||||
import {
|
||||
EXCHANGE_PIPELINE_TASK_FANOUT,
|
||||
QUEUE_HANDLE_PIPELINE_TASK_LOG_EVENT,
|
||||
ROUTE_PIPELINE_TASK_LOG,
|
||||
} from './pipeline-tasks.constants';
|
||||
|
||||
@Injectable()
|
||||
export class PipelineTaskLogger implements OnModuleDestroy {
|
||||
private readonly messageSubject = new Subject<PipelineTaskEvent>();
|
||||
private readonly message$: Observable<PipelineTaskEvent> = this.messageSubject.pipe();
|
||||
@RabbitSubscribe({
|
||||
exchange: EXCHANGE_PIPELINE_TASK_FANOUT,
|
||||
routingKey: ROUTE_PIPELINE_TASK_LOG,
|
||||
queue: QUEUE_HANDLE_PIPELINE_TASK_LOG_EVENT,
|
||||
})
|
||||
async handleEvent(message: PipelineTaskEvent) {
|
||||
this.messageSubject.next(message);
|
||||
}
|
||||
|
||||
getMessage$(taskId: string) {
|
||||
return this.message$.pipe(
|
||||
tap((val) => console.log(val)),
|
||||
filter((event) => event.taskId === taskId),
|
||||
);
|
||||
}
|
||||
|
||||
onModuleDestroy() {
|
||||
this.messageSubject.complete();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user