Browse Source

async

master
zeus 4 years ago
parent
commit
68797e3cfa
  1. 158
      swarmlab-app/src/run/app.js

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

@ -420,25 +420,25 @@ function getSHA256ofJSON(input){
function onCollection(err, collection) { function onCollection(err, collection) {
let options = { tailable: true, let options = { tailable: true,
awaitdata: true, awaitdata: true,
numberOfRetries: -1, numberOfRetries: -1,
tailableRetryInterval: 500 tailableRetryInterval: 500
}; };
var cursor = collection.find({},options).stream(); var cursor = collection.find({},options).stream();
var itemsProcessed = 0; var itemsProcessed = 0;
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) {
(async() => {
var issendob = {}; var issendob = {};
issendob.message = data.message issendob.message = data.message
issendob.tailed_path = data.tailed_path issendob.tailed_path = data.tailed_path
var issend = getSHA256ofJSON(issendob) var issend = getSHA256ofJSON(issendob)
//io.in('anagnostopoulos@uniwa.gr').emit("logdata", data);
console.log('++++++++' + JSON.stringify(data)); console.log('++++++++' + JSON.stringify(data));
var pathfileval = pathmodule.basename(data.tailed_path); var pathfileval = pathmodule.basename(data.tailed_path);
var arrfile = pathfileval.toString().split("-"); var arrfile = pathfileval.toString().split("-");
@ -446,76 +446,72 @@ function onCollection(err, collection) {
var indexupdate = "yes" var indexupdate = "yes"
var resob = {} var resob = {}
//var indexfind1 = global.pipelines.findIndex(x => x.pathlogfile==pathfileval); await 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" ){ var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto
(async() => { var resdata = await getpipelines(token,pathfile)
var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto resob.pathlogfile = pathfileval
var resdata = await getpipelines(token,pathfile) var resobarray = []
resob.pathlogfile = pathfileval var resob1 = {}
var resobarray = [] var i = 0
var resob1 = {} resob1.data = resdata.data[i].res25swarmlabname
var i = 0 resob1.user25user = resdata.data[i].res25user
resob1.data = resdata.data[i].res25swarmlabname resob1.res25creator = resdata.data[i].res25creator
resob1.user25user = resdata.data[i].res25user resob1.res25fileforce = resdata.data[i].res25fileforce
resob1.res25creator = resdata.data[i].res25creator resob1.tailed_path = pathfileval
resob1.res25fileforce = resdata.data[i].res25fileforce var resob1string = JSON.stringify(resob1);
resob1.tailed_path = pathfileval pubClient.set(pathfileval, resob1string, function(err, res) {
var resob1string = JSON.stringify(resob1);
pubClient.set(pathfileval, resob1string, function(err, res) {
});
reslog.data = resob1
reslog.log = data
reslog.date = convertDateToUTC(now)
var user = resob1.res25creator
console.log('datauser ' + JSON.stringify(user));
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(reslog));
pubClient.get(issend, function(err, object) {
if(err == null){
pubClient.set(issend, itemsProcessed, function(err, res) {
io.in(user).emit("logdata", reslog);
}); });
} reslog.data = resob1
itemsProcessed++; reslog.log = data
}); reslog.date = convertDateToUTC(now)
})() var user = resob1.res25creator
}else{ console.log('datauser ' + JSON.stringify(user));
pubClient.get(pathfileval, function(err, object) { console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(reslog));
var objecttmp = JSON.parse(object); await pubClient.get(issend, function(err, object) {
var resob1 = {} if(err == null){
resob1.data = objecttmp.res25swarmlabname pubClient.set(issend, itemsProcessed, function(err, res) {
resob1.user25user = objecttmp.res25user
resob1.res25creator = objecttmp.res25creator
resob1.res25fileforce = objecttmp.res25fileforce
resob1.tailed_path = objecttmp.tailed_path
reslog.data = resob1
reslog.log = data
reslog.date = convertDateToUTC(now)
console.log('<<<<<<<<<<<---------------------<<<<<<<<<<<<<<<---------------------------<<<<<<<<<<<< '+JSON.stringify(object));
console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< '+JSON.stringify(reslog));
var user = objecttmp.user25user
//io.join(user);
//io.to(user).emit(reslog);
pubClient.get(issend, function(err, object) {
if(err == null){
pubClient.set(issend, itemsProcessed, function(err, res) {
io.in(user).emit("logdata", reslog); io.in(user).emit("logdata", reslog);
}); });
} }
itemsProcessed++; itemsProcessed++;
}); });
}); }else{
} await pubClient.get(pathfileval, function(err, object) {
}); var objecttmp = JSON.parse(object);
var resob1 = {}
resob1.data = objecttmp.res25swarmlabname
resob1.user25user = objecttmp.res25user
resob1.res25creator = objecttmp.res25creator
resob1.res25fileforce = objecttmp.res25fileforce
resob1.tailed_path = objecttmp.tailed_path
reslog.data = resob1
reslog.log = data
reslog.date = convertDateToUTC(now)
console.log('<<<<<<<<<<<---------------------<<<<<<<<<<<<<<<---------------------------<<<<<<<<<<<< '+JSON.stringify(object));
console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< '+JSON.stringify(reslog));
var user = objecttmp.user25user
await pubClient.get(issend, function(err, object) {
if(err == null){
pubClient.set(issend, itemsProcessed, function(err, res) {
io.in(user).emit("logdata", reslog);
});
}
itemsProcessed++;
});
});
}
}); //redis get
})() //async
}); });

Loading…
Cancel
Save