Cleanup ticking intervals

This commit is contained in:
Bel LaPointe
2021-02-28 00:41:53 -06:00
parent aed986661c
commit 0d6a6c7a8a

View File

@@ -1325,6 +1325,7 @@
this.databases.push(arguments[i]);
}
this.deltas = new Deltas(this.cache());
this.intervals = [];
this.scheduleSync();
this.syncCacheWithPrimary();
}
@@ -1367,9 +1368,23 @@
scheduleSync()
{
setInterval(() => { this.syncDeltas(); }, 10 * 1000);
setInterval(() => { this.syncCacheWithPrimary(); }, 120 * 1000);
setInterval(() => { this.syncReplicasWithCache(); }, 123 * 1000);
this.intervals.push(
setInterval(() => { this.syncDeltas(); }, 10 * 1000)
);
this.intervals.push(
setInterval(() => { this.syncCacheWithPrimary(); }, 120 * 1000)
);
this.intervals.push(
setInterval(() => { this.syncReplicasWithCache(); }, 123 * 1000)
);
}
close()
{
this.intervals.forEach((i) => {
clearInterval(i);
});
this.intervals = [];
}
syncDeltas()
@@ -3199,6 +3214,13 @@
function setGlobalNamespace(namespace)
{
try
{
if (globalStorage && globalStorage.close)
globalStorage.close();
}
catch (e) {}
globalStorage = new MultiDatabase(
new NamespacedDatabase(namespace, new HTTPCRUD()),
new NamespacedDatabase(namespace, new Local()),