1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

introduced tests + refactoring

This commit is contained in:
Massimo Candela
2019-07-09 02:46:08 +02:00
parent 9b7de79264
commit 4319fbfea6
21 changed files with 1161 additions and 236 deletions

View File

@@ -1,23 +1,29 @@
import { config, logger, input } from "./env";
import cluster from "cluster";
import { config, logger, input, pubSub } from "./env";
import Consumer from "./consumer";
import ConnectorFactory from "./connectorFactory";
import cluster from "cluster";
if (cluster.isMaster) {
const worker = cluster.fork();
function master(worker) {
const connectorFactory = new ConnectorFactory();
connectorFactory.loadConnectors();
connectorFactory.connectConnectors()
return connectorFactory.connectConnectors()
.then(() => {
for (const connector of connectorFactory.getConnectors()) {
connector.onMessage((message) => {
worker.send(connector.name + "-" + message);
});
if (worker){
connector.onMessage((message) => {
worker.send(connector.name + "-" + message);
});
} else {
connector.onMessage((message) => {
pubSub.publish("data", connector.name + "-" + message);
});
}
connector.onError(error => {
logger.log({
level: 'error',
@@ -39,8 +45,20 @@ if (cluster.isMaster) {
message: error
});
});
}
module.exports = pubSub;
console.log("RUNNING ENVIRONMENT:", config.environment);
if (config.environment === "test") {
master();
new Consumer();
} else {
new Consumer();
if (cluster.isMaster) {
master(cluster.fork());
} else {
new Consumer();
}
}