mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-03 01:18:43 +02:00
Merge pull request #265 from Unleash/cleanup_timers
Clean up intervals.
This commit is contained in:
commit
2ae863cfed
@ -12,6 +12,8 @@ const COLUMNS = [
|
|||||||
];
|
];
|
||||||
const TABLE = 'client_instances';
|
const TABLE = 'client_instances';
|
||||||
|
|
||||||
|
const ONE_DAY = 24 * 61 * 60 * 1000;
|
||||||
|
|
||||||
const mapRow = row => ({
|
const mapRow = row => ({
|
||||||
appName: row.app_name,
|
appName: row.app_name,
|
||||||
instanceId: row.instance_id,
|
instanceId: row.instance_id,
|
||||||
@ -21,19 +23,12 @@ const mapRow = row => ({
|
|||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
});
|
});
|
||||||
|
|
||||||
// const mapAppsRow = (row) => ({
|
|
||||||
// appName: row.app_name,
|
|
||||||
// createdAt: row.created_at,
|
|
||||||
// });
|
|
||||||
|
|
||||||
class ClientInstanceStore {
|
class ClientInstanceStore {
|
||||||
constructor(db) {
|
constructor(db) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
setTimeout(() => this._removeInstancesOlderThanTwoDays(), 10).unref();
|
const clearer = () => this._removeInstancesOlderThanTwoDays();
|
||||||
setInterval(
|
setTimeout(clearer, 10).unref();
|
||||||
() => this._removeInstancesOlderThanTwoDays(),
|
setInterval(clearer, ONE_DAY).unref();
|
||||||
24 * 61 * 60 * 1000
|
|
||||||
).unref();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_removeInstancesOlderThanTwoDays() {
|
_removeInstancesOlderThanTwoDays() {
|
||||||
|
@ -5,6 +5,8 @@ const logger = require('../logger')('client-metrics-db.js');
|
|||||||
const METRICS_COLUMNS = ['id', 'created_at', 'metrics'];
|
const METRICS_COLUMNS = ['id', 'created_at', 'metrics'];
|
||||||
const TABLE = 'client_metrics';
|
const TABLE = 'client_metrics';
|
||||||
|
|
||||||
|
const ONE_MINUTE = 60 * 1000;
|
||||||
|
|
||||||
const mapRow = row => ({
|
const mapRow = row => ({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
@ -16,11 +18,9 @@ class ClientMetricsDb {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
|
|
||||||
// Clear old metrics regulary
|
// Clear old metrics regulary
|
||||||
setTimeout(() => this.removeMetricsOlderThanOneHour(), 10).unref();
|
const clearer = () => this.removeMetricsOlderThanOneHour();
|
||||||
setInterval(
|
setTimeout(clearer, 10).unref();
|
||||||
() => this.removeMetricsOlderThanOneHour(),
|
setInterval(clearer, ONE_MINUTE).unref();
|
||||||
60 * 1000
|
|
||||||
).unref();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeMetricsOlderThanOneHour() {
|
removeMetricsOlderThanOneHour() {
|
||||||
|
Loading…
Reference in New Issue
Block a user