remove asynchronisity checks

This commit is contained in:
Unitech 2016-04-01 19:52:49 +02:00
parent ba0d36dc3f
commit 14bcb363f0

View File

@ -122,13 +122,9 @@ var PushInteractor = module.exports = {
startPoolingWorker : function() {
var self = this;
setTimeout(function() {
(function operate() {
debug('[PUSH] +---- Pooling: sending data ----+');
PushInteractor.sendData(function() {
setTimeout(operate, cst.SEND_INTERVAL);
});
})();
setInterval(function() {
debug('[PUSH] +---- Pooling: sending data ----+');
PushInteractor.sendData();
}, cst.SEND_INTERVAL);
},
/**
@ -218,7 +214,7 @@ var PushInteractor = module.exports = {
if (packet.process && !packet.server) {
if (event === 'logs'
&& (JSON.stringify(self._packet[event]).length > logs_limit_size
|| self._packet[event].length > 100))
|| self._packet[event].length > 100))
return console.error('Logs packet larger than 50KB limit');
self._packet[event].push(packet);
@ -261,6 +257,12 @@ var PushInteractor = module.exports = {
sendData : function(cb) {
var self = this;
if (self.conf._connection_is_up === false) {
debug('[CRITICAL] Connection is down, skipping data');
self.resetPacket();
return false;
}
this.preparePacket(function() {
var data = {};
@ -283,57 +285,22 @@ var PushInteractor = module.exports = {
}
var str = JSON.stringify(data);
var t1 = new Date();
self.resetPacket();
if (self.conf._connection_is_up === true) {
var t1 = new Date();
if (!self.socket) return false;
var _cb_called = false;
self.socket.client.sendv2(str, function() {
var duration_sec = (new Date() - t1) / 1000;
debugInfo('Time to flush data %ds', duration_sec);
/**
* Avoid that too much data get buffered in case of offline
*/
var timer = setTimeout(function() {
console.error('[FALLBACK] Clearing agent data cache to avoid leakage + skip async');
self.resetPacket();
if (duration_sec > 1)
console.info('[WARN] Time to send data over TCP took %dseconds!', duration_sec);
_cb_called = true;
return cb({msg : 'Fallback clear', code : 'TIMEOUT'});
}, 1000 * 30);
if (!self.socket) {
return process.nextTick(function() {
return cb({msg: 'pub socket not defined', code : 'NOTDEFINED'});
});
}
self.socket.client.sendv2(str, function() {
if (_cb_called == true) {
console.info('[FALLBACK] Avoid to re-call async');
return false;
}
clearTimeout(timer);
var duration_sec = (new Date() - t1) / 1000;
debugInfo('Time to flush data %ds', duration_sec);
if (duration_sec > 1)
console.info('[WARN] Time to send data over TCP took %dseconds!', duration_sec);
data = null;
str = null;
return cb();
});
} else {
// If not connected skip data to avoid leakage
debug('[CRITICAL] Connection is down');
data = null;
str = null;
return cb();
}
});
});
}
};