Browse Source

sync redis

master
zeus 4 years ago
parent
commit
967dc94ccf
  1. 82
      swarmlab-app/src/run/app.js

82
swarmlab-app/src/run/app.js

@ -414,6 +414,9 @@ cors(corsOptions), (req, res, next) => {
// socket // socket
// *************************************************** // ***************************************************
function getSHA256ofJSON(input){
return crypto.createHash('sha256').update(JSON.stringify(input)).digest('hex')
}
function onCollection(err, collection) { function onCollection(err, collection) {
@ -428,6 +431,7 @@ function onCollection(err, collection) {
var reslog = new Object(); var reslog = new Object();
var now = new Date(); var now = new Date();
cursor.on('data', function (data) { cursor.on('data', function (data) {
var issend = getSHA256ofJSON(data)
//io.in('anagnostopoulos@uniwa.gr').emit("logdata", data); //io.in('anagnostopoulos@uniwa.gr').emit("logdata", data);
console.log('++++++++' + JSON.stringify(data)); console.log('++++++++' + JSON.stringify(data));
@ -440,38 +444,44 @@ function onCollection(err, collection) {
var resob = {} var resob = {}
//var indexfind1 = global.pipelines.findIndex(x => x.pathlogfile==pathfileval); //var indexfind1 = global.pipelines.findIndex(x => x.pathlogfile==pathfileval);
pubClient.get(pathfileval, function(err, object) { pubClient.get(pathfileval, function(err, object) {
console.log('----------------' + err + '<<<<<<<<<<<<<<<<<<<<<<' + object); console.log('----------------' + err + '<<<<<<<<<<<<<<<<<<<<<<' + object);
if(object){ if(object){
indexupdate = "no" indexupdate = "no"
}else{ }else{
console.log('redis '+JSON.stringify(object)); console.log('redis '+JSON.stringify(object));
} }
console.log('update '+JSON.stringify(indexupdate)); console.log('update '+JSON.stringify(indexupdate));
if (indexupdate == "yes" ){ if (indexupdate == "yes" ){
(async() => { (async() => {
var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto
var resdata = await getpipelines(token,pathfile) var resdata = await getpipelines(token,pathfile)
resob.pathlogfile = pathfileval resob.pathlogfile = pathfileval
var resobarray = [] var resobarray = []
var resob1 = {} var resob1 = {}
var i = 0 var i = 0
resob1.data = resdata.data[i].res25swarmlabname resob1.data = resdata.data[i].res25swarmlabname
resob1.user25user = resdata.data[i].res25user resob1.user25user = resdata.data[i].res25user
resob1.res25creator = resdata.data[i].res25creator resob1.res25creator = resdata.data[i].res25creator
resob1.res25fileforce = resdata.data[i].res25fileforce resob1.res25fileforce = resdata.data[i].res25fileforce
resob1.tailed_path = pathfileval resob1.tailed_path = pathfileval
var resob1string = JSON.stringify(resob1); var resob1string = JSON.stringify(resob1);
pubClient.set(pathfileval, resob1string, function(err, res) { pubClient.set(pathfileval, resob1string, function(err, res) {
}); });
reslog.data = resob1 reslog.data = resob1
reslog.log = data reslog.log = data
reslog.date = convertDateToUTC(now) reslog.date = convertDateToUTC(now)
var user = resob1.res25creator var user = resob1.res25creator
console.log('datauser ' + JSON.stringify(user)); console.log('datauser ' + JSON.stringify(user));
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(reslog)); console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(reslog));
io.in(user).emit("logdata", reslog); pubClient.get(issend, function(err, object) {
itemsProcessed++; if(err == null){
})() pubClient.set(issend, itemsProcessed, function(err, res) {
io.in(user).emit("logdata", reslog);
});
}
itemsProcessed++;
});
})()
}else{ }else{
pubClient.get(pathfileval, function(err, object) { pubClient.get(pathfileval, function(err, object) {
@ -495,8 +505,16 @@ function onCollection(err, collection) {
//console.log("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRr", JSON.stringify(io.sockets.adapter.rooms)); // Set { <socket.id> } //console.log("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRr", JSON.stringify(io.sockets.adapter.rooms)); // Set { <socket.id> }
io.in(user).emit("logdata", reslog); pubClient.get(issend, function(err, object) {
itemsProcessed++; if(err == null){
pubClient.set(issend, itemsProcessed, function(err, res) {
io.in(user).emit("logdata", reslog);
});
}
itemsProcessed++;
});
//io.in(user).emit("logdata", reslog);
//itemsProcessed++;
}); });
} }
}); });

Loading…
Cancel
Save