@@ -65,9 +65,32 @@ const indexProject = Promise.coroutine(function* (logger, msg) { // eslint-disab
65
65
const projectCreatedHandler = Promise . coroutine ( function * ( logger , msg , channel ) { // eslint-disable-line func-names
66
66
const project = JSON . parse ( msg . content . toString ( ) ) ;
67
67
try {
68
- // we don't have to call indexing, as it's now handled by `project-processor-es`
69
- // yield indexProject(logger, msg);
70
- // we call this handle only for the sake of creating topics for the phases
68
+ yield indexProject ( logger , msg ) ;
69
+ if ( project . phases && project . phases . length > 0 ) {
70
+ logger . debug ( 'Phases found for the project, trying to create topics for each phase.' ) ;
71
+ const topicPromises = _ . map ( project . phases , phase => createPhaseTopic ( logger , phase ) ) ;
72
+ yield Promise . all ( topicPromises ) ;
73
+ }
74
+ channel . ack ( msg ) ;
75
+ } catch ( error ) {
76
+ logger . error ( `Error processing event (projectId: ${ project . id } )` , error ) ;
77
+ channel . nack ( msg , false , ! msg . fields . redelivered ) ;
78
+ }
79
+ } ) ;
80
+
81
+ /**
82
+ * Handler for project creation event
83
+ *
84
+ * we call this handle only for the sake of creating topics for the phases
85
+ *
86
+ * @param {Object } logger logger to log along with trace id
87
+ * @param {Object } msg event payload
88
+ * @param {Object } channel channel to ack, nack
89
+ * @returns {undefined }
90
+ */
91
+ const projectCreatedHandlerForPhases = Promise . coroutine ( function * ( logger , msg , channel ) { // eslint-disable-line func-names
92
+ const project = JSON . parse ( msg . content . toString ( ) ) ;
93
+ try {
71
94
if ( project . phases && project . phases . length > 0 ) {
72
95
logger . debug ( 'Phases found for the project, trying to create topics for each phase.' ) ;
73
96
const topicPromises = _ . map ( project . phases , phase => createPhaseTopic ( logger , phase ) ) ;
@@ -192,6 +215,7 @@ async function projectUpdatedKafkaHandler(app, topic, payload) {
192
215
193
216
module . exports = {
194
217
projectCreatedHandler,
218
+ projectCreatedHandlerForPhases,
195
219
projectUpdatedHandler,
196
220
projectDeletedHandler,
197
221
projectUpdatedKafkaHandler,
0 commit comments