File tree 1 file changed +24
-2
lines changed
1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@nestjs/common' ;
2
- import { ICommand , ofType , Saga } from '@nestjs/cqrs' ;
3
- import { map , Observable } from 'rxjs' ;
2
+ import {
3
+ ICommand ,
4
+ ofType ,
5
+ Saga ,
6
+ UnhandledExceptionBus ,
7
+ UnhandledExceptionInfo ,
8
+ } from '@nestjs/cqrs' ;
9
+ import { map , Observable , Subject , takeUntil } from 'rxjs' ;
4
10
import { CreateUserEvent } from '../event' ;
5
11
import { CreateRegisterCouponCommand } from '../command' ;
6
12
7
13
@Injectable ( )
8
14
export class UserSaga {
15
+ private destroy$ = new Subject < void > ( ) ;
16
+
17
+ constructor ( private unhandledExceptionsBus : UnhandledExceptionBus ) {
18
+ this . unhandledExceptionsBus
19
+ . pipe ( takeUntil ( this . destroy$ ) )
20
+ . subscribe ( ( exceptionInfo : UnhandledExceptionInfo ) => {
21
+ console . error ( 'Unhandled exception in saga:' , exceptionInfo ) ;
22
+ // 재시도나 에러 알림 등 처리
23
+ } ) ;
24
+ }
25
+
9
26
/** @Saga () 가 있으면 애플리케이션의 이벤트 스트림을 구독하고 `ofType`으로 처리할 이벤트를 선택 */
10
27
@Saga ( )
11
28
public userCreated ( event$ : Observable < any > ) : Observable < ICommand > {
@@ -15,4 +32,9 @@ export class UserSaga {
15
32
map ( ( event ) => new CreateRegisterCouponCommand ( fakeCouponId , event . id ) ) ,
16
33
) ;
17
34
}
35
+
36
+ onModuleDestroy ( ) {
37
+ this . destroy$ . next ( ) ;
38
+ this . destroy$ . complete ( ) ;
39
+ }
18
40
}
You can’t perform that action at this time.
0 commit comments