2018-01-29 09:07:10 +01:00
|
|
|
import { fetchFeatureMetrics } from './store/feature-metrics-actions';
|
|
|
|
|
|
|
|
class MetricsPoller {
|
|
|
|
constructor(store) {
|
|
|
|
this.store = store;
|
|
|
|
this.timer = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
this.store.subscribe(() => {
|
|
|
|
const features = this.store.getState().features;
|
2018-02-04 22:04:28 +01:00
|
|
|
if (!this.timer && features.size > 0) {
|
2018-01-29 09:07:10 +01:00
|
|
|
this.timer = setInterval(this.fetchMetrics.bind(this), 5000);
|
|
|
|
this.fetchMetrics();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchMetrics() {
|
|
|
|
this.store.dispatch(fetchFeatureMetrics());
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
if (this.timer) {
|
|
|
|
clearTimeout(this.timer);
|
|
|
|
this.timer = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MetricsPoller;
|