Skip to content

[HOTFIX] [DEV] Create phase topics on project create #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/events/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import { EVENT, CONNECT_NOTIFICATION_EVENT } from '../constants';
import { projectCreatedHandler,
projectCreatedHandlerForPhases,
projectUpdatedKafkaHandler } from './projects';
import { projectPhaseAddedHandler, projectPhaseRemovedHandler,
projectPhaseUpdatedHandler } from './projectPhases';
Expand Down Expand Up @@ -39,7 +40,7 @@ const voidRabbitHandler = (logger, msg, channel) => {
// we should completely remove the handlers for this events.
export const rabbitHandlers = {
'project.initial': projectCreatedHandler, // is only used `seedElasticsearchIndex.js` and can be removed
[EVENT.ROUTING_KEY.PROJECT_DRAFT_CREATED]: voidRabbitHandler, // DISABLED
[EVENT.ROUTING_KEY.PROJECT_DRAFT_CREATED]: projectCreatedHandlerForPhases, // we have to call it, because it triggers topics creating for phases
[EVENT.ROUTING_KEY.PROJECT_UPDATED]: voidRabbitHandler, // DISABLED
[EVENT.ROUTING_KEY.PROJECT_DELETED]: voidRabbitHandler, // DISABLED
[EVENT.ROUTING_KEY.PROJECT_MEMBER_ADDED]: voidRabbitHandler, // DISABLED
Expand Down
26 changes: 26 additions & 0 deletions src/events/projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ const projectCreatedHandler = Promise.coroutine(function* (logger, msg, channel)
}
});

/**
* Handler for project creation event
*
* we call this handle only for the sake of creating topics for the phases
*
* @param {Object} logger logger to log along with trace id
* @param {Object} msg event payload
* @param {Object} channel channel to ack, nack
* @returns {undefined}
*/
const projectCreatedHandlerForPhases = Promise.coroutine(function* (logger, msg, channel) { // eslint-disable-line func-names
const project = JSON.parse(msg.content.toString());
try {
if (project.phases && project.phases.length > 0) {
logger.debug('Phases found for the project, trying to create topics for each phase.');
const topicPromises = _.map(project.phases, phase => createPhaseTopic(logger, phase));
yield Promise.all(topicPromises);
}
channel.ack(msg);
} catch (error) {
logger.error(`Error processing event (projectId: ${project.id})`, error);
channel.nack(msg, false, !msg.fields.redelivered);
}
});

/**
* Handler for project updated event
* @param {Object} logger logger to log along with trace id
Expand Down Expand Up @@ -190,6 +215,7 @@ async function projectUpdatedKafkaHandler(app, topic, payload) {

module.exports = {
projectCreatedHandler,
projectCreatedHandlerForPhases,
projectUpdatedHandler,
projectDeletedHandler,
projectUpdatedKafkaHandler,
Expand Down