@@ -86,27 +86,25 @@ const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
86
86
// only one per userHandle
87
87
notifications = _ . uniqBy ( notifications , 'userHandle' ) ;
88
88
89
- return new Promise ( ( resolve , reject ) => { // eslint-disable-line no-unused-vars
90
- const handles = _ . map ( notifications , 'userHandle' ) ;
91
- if ( handles . length > 0 ) {
92
- service . getUsersByHandle ( handles ) . then ( ( users ) => {
93
- _ . forEach ( notifications , ( notification ) => {
94
- const mentionedUser = _ . find ( users , { handle : notification . userHandle } ) ;
95
- notification . userId = mentionedUser ? mentionedUser . userId . toString ( ) : notification . userHandle ;
96
- } ) ;
97
- resolve ( notifications ) ;
98
- } ) . catch ( ( error ) => {
99
- if ( logger ) {
100
- logger . error ( error ) ;
101
- logger . info ( 'Unable to send notification to mentioned user' )
102
- }
103
- //resolves with empty notification which essentially means we are unable to send notification to mentioned user
104
- resolve ( [ ] ) ;
89
+ const handles = _ . map ( notifications , 'userHandle' ) ;
90
+ if ( handles . length > 0 ) {
91
+ return service . getUsersByHandle ( handles ) . then ( ( users ) => {
92
+ _ . forEach ( notifications , ( notification ) => {
93
+ const mentionedUser = _ . find ( users , { handle : notification . userHandle } ) ;
94
+ notification . userId = mentionedUser ? mentionedUser . userId . toString ( ) : notification . userHandle ;
105
95
} ) ;
106
- } else {
107
- resolve ( [ ] ) ;
108
- }
109
- } ) ;
96
+ return Promise . resolve ( notifications ) ;
97
+ } ) . catch ( ( error ) => {
98
+ if ( logger ) {
99
+ logger . error ( error ) ;
100
+ logger . info ( 'Unable to send notification to mentioned user' )
101
+ }
102
+ //resolves with empty notification which essentially means we are unable to send notification to mentioned user
103
+ return Promise . resolve ( [ ] ) ;
104
+ } ) ;
105
+ } else {
106
+ return Promise . resolve ( [ ] ) ;
107
+ }
110
108
} ;
111
109
112
110
/**
@@ -151,7 +149,7 @@ const getProjectMembersNotifications = (eventConfig, project) => {
151
149
return Promise . resolve ( [ ] ) ;
152
150
}
153
151
154
- return new Promise ( ( resolve ) => {
152
+ return Promise . promisify ( ( callback ) => {
155
153
let notifications = [ ] ;
156
154
const projectMembers = _ . get ( project , 'members' , [ ] ) ;
157
155
@@ -186,8 +184,8 @@ const getProjectMembersNotifications = (eventConfig, project) => {
186
184
// only one per userId
187
185
notifications = _ . uniqBy ( notifications , 'userId' ) ;
188
186
189
- resolve ( notifications ) ;
190
- } ) ;
187
+ callback ( null , notifications ) ;
188
+ } ) ( ) ;
191
189
} ;
192
190
193
191
/**
@@ -415,10 +413,10 @@ const handler = (topic, message, logger, callback) => {
415
413
}
416
414
417
415
// get project details
418
- service . getProject ( projectId ) . then ( project => {
416
+ return service . getProject ( projectId ) . then ( project => {
419
417
let allNotifications = [ ] ;
420
418
421
- Promise . all ( [
419
+ return Promise . all ( [
422
420
// the order in this list defines the priority of notification for the SAME user
423
421
// upper in this list - higher priority
424
422
// NOTE: always add all handles here, they have to check by themselves:
@@ -506,5 +504,12 @@ if (config.ENABLE_EMAILS) {
506
504
// notificationServer.logger.error('Notification server errored out');
507
505
// });
508
506
507
+
508
+ process . on ( 'unhandledRejection' , ( reason , promise ) => {
509
+ console . log ( 'Unhandled Rejection at:' , promise , 'reason:' , reason ) ;
510
+ // aborts the process to let the HA of the container to restart the task
511
+ process . abort ( ) ;
512
+ } ) ;
513
+
509
514
// if no need to init database, then directly start the server:
510
515
notificationServer . startKafkaConsumers ( ) ;
0 commit comments