Skip to content

Commit 2ef9ad0

Browse files
committed
fix: keep seedElasticsearchIndex.js working
- we change the previous fix and keep projectCreatedHandler as it is, as `seedElasticsearchIndex.js` relies on it - for out needs we create a copy of `projectCreatedHandler` called `projectCreatedHandlerForPhases` which only take care about topics for phases
1 parent 97ce674 commit 2ef9ad0

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/events/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import { EVENT, CONNECT_NOTIFICATION_EVENT } from '../constants';
33
import { projectCreatedHandler,
4+
projectCreatedHandlerForPhases,
45
projectUpdatedKafkaHandler } from './projects';
56
import { projectPhaseAddedHandler, projectPhaseRemovedHandler,
67
projectPhaseUpdatedHandler } from './projectPhases';
@@ -39,7 +40,7 @@ const voidRabbitHandler = (logger, msg, channel) => {
3940
// we should completely remove the handlers for this events.
4041
export const rabbitHandlers = {
4142
'project.initial': projectCreatedHandler, // is only used `seedElasticsearchIndex.js` and can be removed
42-
[EVENT.ROUTING_KEY.PROJECT_DRAFT_CREATED]: projectCreatedHandler, // we have to call it, because it triggers topics creating for phases
43+
[EVENT.ROUTING_KEY.PROJECT_DRAFT_CREATED]: projectCreatedHandlerForPhases, // we have to call it, because it triggers topics creating for phases
4344
[EVENT.ROUTING_KEY.PROJECT_UPDATED]: voidRabbitHandler, // DISABLED
4445
[EVENT.ROUTING_KEY.PROJECT_DELETED]: voidRabbitHandler, // DISABLED
4546
[EVENT.ROUTING_KEY.PROJECT_MEMBER_ADDED]: voidRabbitHandler, // DISABLED

src/events/projects/index.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,32 @@ const indexProject = Promise.coroutine(function* (logger, msg) { // eslint-disab
6565
const projectCreatedHandler = Promise.coroutine(function* (logger, msg, channel) { // eslint-disable-line func-names
6666
const project = JSON.parse(msg.content.toString());
6767
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 {
7194
if (project.phases && project.phases.length > 0) {
7295
logger.debug('Phases found for the project, trying to create topics for each phase.');
7396
const topicPromises = _.map(project.phases, phase => createPhaseTopic(logger, phase));
@@ -192,6 +215,7 @@ async function projectUpdatedKafkaHandler(app, topic, payload) {
192215

193216
module.exports = {
194217
projectCreatedHandler,
218+
projectCreatedHandlerForPhases,
195219
projectUpdatedHandler,
196220
projectDeletedHandler,
197221
projectUpdatedKafkaHandler,

0 commit comments

Comments
 (0)