1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00

remove internal storage

This commit is contained in:
sveisvei 2016-11-04 16:17:11 +01:00
parent ab201db754
commit cd5c2e3914

View File

@ -3,42 +3,32 @@
const POLL_INTERVAL = 10000; const POLL_INTERVAL = 10000;
const { EventEmitter } = require('events'); const { EventEmitter } = require('events');
module.exports = class UnleashClientMetricsService extends EventEmitter { module.exports = class UnleashClientMetrics extends EventEmitter {
constructor (metricsDb) { constructor (metricsDb) {
super(); super();
this.metricsDb = metricsDb; this.db = metricsDb;
this.metrics = [];
this.highestIdSeen = 0; this.highestIdSeen = 0;
this.fetch(); this.db.getMetricsLastWeek().then(metrics => {
} this.addMetrics(metrics);
this.startPoller();
fetch () { });
return this.metricsDb
.getNewMetrics(this.highestIdSeen)
.then(metrics => {
this.startTimer();
this.addMetrics(metrics);
return metrics;
});
} }
addMetrics (metrics) { addMetrics (metrics) {
metrics.forEach(m => this.metrics.push(m)); if (metrics && metrics.length > 0) {
if (this.metrics && this.metrics.length > 0) { this.highestIdSeen = metrics[metrics.length - 1].id;
this.highestIdSeen = this.metrics[this.metrics.length - 1].id;
} }
this.emit('metrics', metrics); this.emit('metrics', metrics);
} }
startTimer () { startPoller () {
setInterval(() => this.fetch(), POLL_INTERVAL).unref(); setInterval(() => {
} this.db.getNewMetrics(this.highestIdSeen)
.then(metrics => this.addMetrics(metrics));
getMetrics () { }, POLL_INTERVAL).unref();
return this.metrics;
} }
insert (metrics) { insert (metrics) {
return this.metricsDb.insert(metrics); return this.db.insert(metrics);
} }
}; };