@@ -11,10 +11,14 @@ const ES_PROJECT_INDEX = config.get('elasticsearchConfig.indexName');
11
11
const ES_PROJECT_TYPE = config . get ( 'elasticsearchConfig.docType' ) ;
12
12
const eClient = util . getElasticSearchClient ( ) ;
13
13
14
-
15
-
16
-
17
- const indexProject = Promise . coroutine ( function * ( logger , msg ) {
14
+ /**
15
+ * Indexes the project in the elastic search.
16
+ *
17
+ * @param {Object } logger logger to log along with trace id
18
+ * @param {Object } msg event payload which is essentially a project in JSON format
19
+ * @returns {undefined }
20
+ */
21
+ const indexProject = Promise . coroutine ( function * ( logger , msg ) { // eslint-disable-line func-names
18
22
const data = JSON . parse ( msg . content . toString ( ) ) ;
19
23
const userIds = data . members ? data . members . map ( single => `userId:${ single . userId } ` ) : [ ] ;
20
24
try {
@@ -23,8 +27,7 @@ const indexProject = Promise.coroutine(function* (logger, msg) {
23
27
// if no members are returned than this should result in nack
24
28
if ( ! _ . isArray ( memberDetails ) || memberDetails . length === 0 ) {
25
29
logger . error ( `Empty member details for userIds ${ userIds . join ( ',' ) } requeing the message` ) ;
26
- channel . nack ( msg , false , ! msg . fields . redelivered ) ;
27
- return undefined ;
30
+ throw new Error ( `Empty member details for userIds ${ userIds . join ( ',' ) } requeing the message` ) ;
28
31
}
29
32
// update project member record with details
30
33
data . members = data . members . map ( ( single ) => {
@@ -39,7 +42,6 @@ const indexProject = Promise.coroutine(function* (logger, msg) {
39
42
body : data ,
40
43
} ) ;
41
44
logger . debug ( `project indexed successfully (projectId: ${ data . id } )` , result ) ;
42
- return undefined ;
43
45
} catch ( error ) {
44
46
logger . error ( `Error indexing project (projectId: ${ data . id } )` , error ) ;
45
47
throw error ;
@@ -54,14 +56,14 @@ const indexProject = Promise.coroutine(function* (logger, msg) {
54
56
* @returns {undefined }
55
57
*/
56
58
const projectCreatedHandler = Promise . coroutine ( function * ( logger , msg , channel ) { // eslint-disable-line func-names
59
+ const project = JSON . parse ( msg . content . toString ( ) ) ;
57
60
try {
58
- indexProject ( logger , msg ) ;
59
- createPhaseTopic ( logger , msg ) ;
61
+ yield indexProject ( logger , msg ) ;
62
+ yield createPhaseTopic ( logger , msg ) ;
60
63
channel . ack ( msg ) ;
61
- } catch ( error ) {
62
- logger . error ( `Error processing event (projectId: ${ data . id } )` , error ) ;
64
+ } catch ( error ) {
65
+ logger . error ( `Error processing event (projectId: ${ project . id } )` , error ) ;
63
66
channel . nack ( msg , false , ! msg . fields . redelivered ) ;
64
- return undefined ;
65
67
}
66
68
} ) ;
67
69
0 commit comments