Skip to content
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

Code clean up #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ require("./healthCheck")(app);

global.config = require("./config");
require("./config/globals")();
require("./generics/scheduler");

let router = require("./routes");

Expand Down
50 changes: 0 additions & 50 deletions config/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ module.exports = function () {
process.env.ENABLE_DEBUG_LOGGING
|| process.env.DEFAULT_ENABLE_DEBUG_LOGGING;

global.locales = [];

global.httpStatusCode =
require(ROOT_PATH + process.env.PATH_TO_HTTP_STATUS_CODE);

Expand Down Expand Up @@ -97,15 +95,6 @@ module.exports = function () {
}
});

// load language files
fs.readdirSync(ROOT_PATH + process.env.LANGUAGE_PATH)
.forEach(function (file) {
if (file.match(/\.json$/) !== null) {
var name = file.replace('.json', '');
global.locales.push(name)
}
});

// Load all kafka consumer files
fs.readdirSync(ROOT_PATH + process.env.PATH_TO_KAFKA_CONSUMERS)
.forEach(function (file) {
Expand Down Expand Up @@ -145,43 +134,4 @@ module.exports = function () {
});

global.sessions = {};

// <- Dirty fix. Not required currently.

// let versions = new Promise(async function(resolve, reject) {

// let versions = await database.models.appReleases.find({
// status:"active"
// }).lean();

// resolve(versions);

// });

// versions.then(function( versionData ) {

// if( versionData.length > 0 ) {
// versionData.forEach(value=>{

// global.sessions[`allAppVersion-${value.appName}-${value.os}`] = {
// is_read : false,
// internal : true,
// action : "versionUpdate",
// appName : value.appName,
// text : value.text,
// title : value.title,
// type : "Information",
// payload : {
// appVersion : value.version,
// updateType : value.releaseType,
// type : "appUpdate",
// os : value.os,
// releaseNotes : value.releaseNotes
// },
// appType : value.appType
// };
// })
// }
// });

};
56 changes: 3 additions & 53 deletions config/kafka-config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
//dependencies
let kafka = require('kafka-node');

const LANGUAGE_TOPIC = process.env.LANGUAGE_TOPIC ||
process.env.DEFAULT_LANGUAGE_TOPIC;

const EMAIL_TOPIC = process.env.EMAIL_TOPIC ||
process.env.DEFAULT_EMAIL_TOPIC;

const NOTIFICATIONS_TOPIC = process.env.NOTIFICATIONS_TOPIC ||
process.env.DEFAULT_NOTIFICATIONS_TOPIC;

const APPLICATION_CONFIG_TOPIC = process.env.APPLICATION_CONFIG_TOPIC ||
process.env.DEFAULT_APPLICATION_CONFIG_TOPIC;

const IMPROVEMENT_PROJECT_NOTIFICATIONS_TOPIC =
process.env.IMPROVEMENT_PROJECT_NOTIFICATIONS_TOPIC;

/**
* Kafka configuration.
* @function
Expand Down Expand Up @@ -47,33 +35,11 @@ var connect = function (config) {
logger.error("Kafka producer creation error!");
})


_sendToKafkaConsumers(
config.topics["notificationsTopic"],
config.host
);

_sendToKafkaConsumers(
config.topics["languagesTopic"],
config.host
);

_sendToKafkaConsumers(
config.topics["emailTopic"],
config.host
);

_sendToKafkaConsumers(
config.topics["appConfigTopic"],
config.host
);

_sendToKafkaConsumers(
config.topics["improvementProjectTopic"],
config.host
);


return {
kafkaProducer: producer,
kafkaConsumer: kafka.Consumer,
Expand Down Expand Up @@ -104,31 +70,15 @@ var _sendToKafkaConsumers = function (topic,host) {
);

consumer.on('message', async function (message) {

if (message && message.topic === APPLICATION_CONFIG_TOPIC) {
applicationconfigConsumer.messageReceived(message);
} else if (message && message.topic === LANGUAGE_TOPIC) {
languagesConsumer.messageReceived(message);
} else if (message && message.topic === EMAIL_TOPIC) {
if (message && message.topic === EMAIL_TOPIC) {
emailConsumer.messageReceived(message, consumer);
} else if (message && message.topic === NOTIFICATIONS_TOPIC) {
inappnotificationsConsumer.messageReceived(message);
pushnotificationsConsumer.messageReceived(message);
}
});

consumer.on('error', async function (error) {

if(error.topics && error.topics[0] === APPLICATION_CONFIG_TOPIC) {
applicationconfigConsumer.errorTriggered(error);
} else if (error.topics && error.topics[0] === LANGUAGE_TOPIC) {
languagesConsumer.errorTriggered(error);
} else if (error.topics && error.topics[0] === EMAIL_TOPIC) {
if (error.topics && error.topics[0] === EMAIL_TOPIC) {
emailConsumer.errorTriggered(error);
} else if(error.topics && error.topics[0] === NOTIFICATIONS_TOPIC){
inappnotificationsConsumer.errorTriggered(error);
pushnotificationsConsumer.errorTriggered(error);
}
}
});

}
Expand Down
Loading