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

Staging #3

Closed
wants to merge 6 commits into from
Closed
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
10 changes: 8 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ let sha3 = require('js-sha3');
let elliptic = require('elliptic');
let ec = new elliptic.ec('secp256k1');

const Config = require('./config');

let mongoURL = "mongodb://localhost:27017";
let instanceId = process.env.instanceId;
let remoteMongoURL = process.env.MONGO_URL || "mongo.default.svc.cluster.local:27017";

let db = null;

process.on('uncaughtException', function (error) {
console.log(error);
});

MongoClient.connect(mongoURL, {reconnectTries : Number.MAX_VALUE, autoReconnect : true}, function(err, database) {
if(!err) {
db = database.db("admin");
}
})

MongoClient.connect(remoteMongoURL, {reconnectTries : Number.MAX_VALUE, autoReconnect : true}, function(err, database) {
MongoClient.connect(Config.getMongoConnectionString(), {reconnectTries : Number.MAX_VALUE, autoReconnect : true}, function(err, database) {
if(!err) {
let tempDB = database.db("admin");
let tempDB = database.db(Config.getDatabase());
function reRun() {
tempDB.collection("networks").findOne({instanceId: instanceId}, function(err, node) {
if(!err && node) {
Expand Down
20 changes: 20 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
mongoUrl: process.env.MONGO_URL || "mongo.default.svc.cluster.local:27017",
getMongoConnectionString() {
return process.env.MONGO_URL || "mongodb://mongo.default.svc.cluster.local:27017"
},
getDatabase() {
const a = process.env.MONGO_URL;
if(!a){
return "admin";
}
if(a.indexOf("?replica") === -1 ){
return "admin"
}
const db = a.substring(a.lastIndexOf("/")+1, a.lastIndexOf("?replica"));
if(!db){
return "admin";
}
return db;
}
}
6 changes: 3 additions & 3 deletions postStart.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var MongoClient = require("mongodb").MongoClient;
let instanceId = process.env.instanceId;
let mongoURL = process.env.MONGO_URL || "mongo.default.svc.cluster.local:27017";
const Config = require('./config');

MongoClient.connect(mongoURL, {reconnectTries : Number.MAX_VALUE, autoReconnect : true, useNewUrlParser: true}, function(err, database) {
MongoClient.connect(Config.getMongoConnectionString(), {reconnectTries : Number.MAX_VALUE, autoReconnect : true, useNewUrlParser: true}, function(err, database) {
if(!err) {
let db = database.db("admin");
let db = database.db(Config.getDatabase());

db.collection("networks").findOne({instanceId: instanceId}, function(err, node) {
if(!err && node) {
Expand Down
6 changes: 3 additions & 3 deletions preStop.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var MongoClient = require("mongodb").MongoClient;
let instanceId = process.env.instanceId;
let mongoURL = process.env.MONGO_URL || "mongo.default.svc.cluster.local:27017";
const Config = require('./config');

MongoClient.connect(mongoURL, {reconnectTries : Number.MAX_VALUE, autoReconnect : true, useNewUrlParser: true}, function(err, database) {
MongoClient.connect(Config.getMongoConnectionString(), {reconnectTries : Number.MAX_VALUE, autoReconnect : true, useNewUrlParser: true}, function(err, database) {
if(!err) {
let db = database.db("admin");
let db = database.db(Config.getDatabase());
db.collection("networks").updateOne({instanceId: instanceId}, { $set: {impulseStatus: "down"}}, function(err, res) {
process.exit(0);
});
Expand Down