Skip to content
Browse files

making sync interval happen AFTER sync is complete via timeout instea…

…d of interval
  • Loading branch information...
1 parent 392bc0a commit 2b95fe38703b6e65687cc6e4e8118718c2ddf2b7 @jeffsu committed
Showing with 16 additions and 11 deletions.
  1. +0 −6 lib/client.ms
  2. +16 −5 lib/server.ms
View
6 lib/client.ms
@@ -43,12 +43,6 @@ export class Client {
return redis.createClient(config);
}
- function inc(name, n) {
- n = n || 1;
- var data = this.getData(name);
- data.inc(name, n);
- }
-
function getStats(name) {
return this.stats[name] || (this.stats[name] = new Stats());
}
View
21 lib/server.ms
@@ -25,17 +25,24 @@ export class Server {
return services;
}
- function sync(redis, time) {
+ function sync(redis, time, cb) {
+ var count = 0;
+ function fin() {
+ if (--count == 0) return cb ? cb() : null;
+ }
+
for (var serviceName in this.services) {
var service = this.services[serviceName];
for (var sensorName in service.sensors) {
var sensor = service.sensors[sensorName];
- sensor.sync(time, redis, "upbeat:services:" + serviceName + ":" + sensorName);
+ count++;
+ sensor.sync(time, redis, "upbeat:services:" + serviceName + ":" + sensorName, fin);
}
}
for (var k in this.stats) {
- this.stats[k].syncTime(time, redis, k);
+ count++;
+ this.stats[k].syncTime(time, redis, k, fin);
}
}
@@ -102,11 +109,15 @@ export class Server {
function setSyncInterval(time, interval, redis) {
function run() {
if (self.status != 'running') return;
- if (self.redisConnected) self.sync(redis, time);
+ if (self.redisConnected) self.sync(redis, time, beat);
+ else beat();
+ }
+
+ function beat() {
+ setTimeout(run, interval);
}
self.toRun.push(run);
- setInterval(run, interval);
}
function buildService(name, config) {

0 comments on commit 2b95fe3

Please sign in to comment.
Something went wrong with that request. Please try again.