@@ -11,10 +11,14 @@ const ES_PROJECT_INDEX = config.get('elasticsearchConfig.indexName');
1111const ES_PROJECT_TYPE = config . get ( 'elasticsearchConfig.docType' ) ;
1212const eClient = util . getElasticSearchClient ( ) ;
1313
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
1822 const data = JSON . parse ( msg . content . toString ( ) ) ;
1923 const userIds = data . members ? data . members . map ( single => `userId:${ single . userId } ` ) : [ ] ;
2024 try {
@@ -23,8 +27,7 @@ const indexProject = Promise.coroutine(function* (logger, msg) {
2327 // if no members are returned than this should result in nack
2428 if ( ! _ . isArray ( memberDetails ) || memberDetails . length === 0 ) {
2529 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` ) ;
2831 }
2932 // update project member record with details
3033 data . members = data . members . map ( ( single ) => {
@@ -39,7 +42,6 @@ const indexProject = Promise.coroutine(function* (logger, msg) {
3942 body : data ,
4043 } ) ;
4144 logger . debug ( `project indexed successfully (projectId: ${ data . id } )` , result ) ;
42- return undefined ;
4345 } catch ( error ) {
4446 logger . error ( `Error indexing project (projectId: ${ data . id } )` , error ) ;
4547 throw error ;
@@ -54,14 +56,14 @@ const indexProject = Promise.coroutine(function* (logger, msg) {
5456 * @returns {undefined }
5557 */
5658const projectCreatedHandler = Promise . coroutine ( function * ( logger , msg , channel ) { // eslint-disable-line func-names
59+ const project = JSON . parse ( msg . content . toString ( ) ) ;
5760 try {
58- indexProject ( logger , msg ) ;
59- createPhaseTopic ( logger , msg ) ;
61+ yield indexProject ( logger , msg ) ;
62+ yield createPhaseTopic ( logger , msg ) ;
6063 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 ) ;
6366 channel . nack ( msg , false , ! msg . fields . redelivered ) ;
64- return undefined ;
6567 }
6668} ) ;
6769
0 commit comments