1
1
import { Injectable , Logger } from '@nestjs/common' ;
2
2
import { ZeromqService } from './zeromq/zeromq.service' ;
3
- import { Process } from '@letsflow/core/process' ;
3
+ import { Process , Notify } from '@letsflow/core/process' ;
4
4
import { ConfigService } from '../common/config/config.service' ;
5
- import { NotifyArgs , NotifyProvider } from './interfaces' ;
5
+ import { NotifyProvider } from './interfaces' ;
6
6
7
7
@Injectable ( )
8
8
export class NotifyService implements NotifyProvider {
@@ -14,29 +14,30 @@ export class NotifyService implements NotifyProvider {
14
14
15
15
async invoke ( process : Process ) : Promise < void > {
16
16
for ( const args of process . current . notify ) {
17
+ if ( 'if' in args && ! args . if ) continue ;
17
18
await this . notify ( process , args ) ;
18
19
}
19
20
}
20
21
21
- async notify ( process : Process , args : NotifyArgs ) : Promise < void > {
22
+ async notify ( process : Process , args : Notify ) : Promise < void > {
22
23
try {
23
24
await this . getProvider ( args . method ) . notify ( process , args ) ;
24
25
} catch ( err ) {
25
26
this . logger . error ( err . message ) ;
26
27
}
27
28
}
28
29
29
- private getProvider ( method : string ) : NotifyProvider {
30
- const settings = this . config . get ( 'notificationMethods ' ) [ method ] ;
30
+ private getProvider ( service : string ) : NotifyProvider {
31
+ const settings = this . config . get ( 'services ' ) [ service ] ;
31
32
32
- if ( ! settings ) throw new Error ( `Notification method '${ method } ' not configured` ) ;
33
- if ( ! settings . provider ) throw new Error ( `Provider not specified for notification method '${ method } '` ) ;
33
+ if ( ! settings ) throw new Error ( `Service '${ service } ' not configured` ) ;
34
+ if ( ! settings . provider ) throw new Error ( `Provider not specified for service '${ service } '` ) ;
34
35
35
36
switch ( settings . provider ) {
36
37
case 'zeromq' :
37
38
return this . zeromq ;
38
39
default :
39
- throw new Error ( `Unsupported provider ${ settings . provider } for notification method '${ method } '` ) ;
40
+ throw new Error ( `Unsupported provider ${ settings . provider } for service '${ service } '` ) ;
40
41
}
41
42
}
42
43
}
0 commit comments