From f7186e0b3ce95a04a1213464e527539f3773d045 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 28 Apr 2015 17:42:44 +0300 Subject: [PATCH] added history request timeout --- app.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 2bfb45b..2dd91de 100644 --- a/app.js +++ b/app.js @@ -4,6 +4,7 @@ var path = require('path'); var favicon = require('serve-favicon'); var bodyParser = require('body-parser'); var askedForHistory = false; +var askedForHistoryTime = 0; var Primus = require('primus'), api, @@ -63,13 +64,14 @@ api.on('connection', function(spark) { var info = Nodes.add(data); spark.emit('ready'); - if(Nodes.getHistory().requiresUpdate() && !askedForHistory && Nodes.canNodeUpdate(data.id)) + if(Nodes.getHistory().requiresUpdate() && Nodes.canNodeUpdate(data.id) && (!askedForHistory || (new Date()).getTime() - askedForHistoryTime > 120000)) { var range = Nodes.getHistory().getHistoryRequestInterval(); console.log("asked " + data.id + " for history"); console.log('interval', range); spark.emit('history', range); askedForHistory = true; + askedForHistoryTime = (new Date()).getTime(); } client.write({action: 'add', data: info}); @@ -90,13 +92,14 @@ api.on('connection', function(spark) { client.write({action: 'charts', data: Nodes.getCharts()}); } - if(Nodes.getHistory().requiresUpdate() && !askedForHistory && Nodes.canNodeUpdate(data.id)) + if(Nodes.getHistory().requiresUpdate() && Nodes.canNodeUpdate(data.id) && (!askedForHistory || (new Date()).getTime() - askedForHistoryTime > 120000)) { var range = Nodes.getHistory().getHistoryRequestInterval(); console.log("asked " + data.id + " for history"); console.log('interval', range); spark.emit('history', range); askedForHistory = true; + askedForHistoryTime = (new Date()).getTime(); } } });