reconfigured monitor

This commit is contained in:
Mason Houtz
2021-01-20 11:58:49 -08:00
parent 2cd26e662d
commit 0b09b79a6e
2 changed files with 19 additions and 16 deletions
@@ -6,30 +6,30 @@ import { loadHistoryContents } from "../../caching";
// prettier-ignore
export const loadContents = (cfg = {}) => {
const {
windowSize,
initialInterval = 3 * 1000,
maxInterval = 10 * initialInterval,
disablePoll = false,
const {
windowSize,
initialInterval = 2 * 1000,
maxInterval = 10 * initialInterval,
disablePoll = false
} = cfg;
return switchMap(([{id}, params, hid]) => {
return switchMap(([{ id }, params, hid]) => {
// a single history update
const singleLoad$ = defer(() => of([id, params, hid]).pipe(
loadHistoryContents({ windowSize }),
));
const singleLoad$ = of([id, params, hid]).pipe(
loadHistoryContents({ windowSize })
);
// start repeating, delay gets longer over time until unsubscribed
const freshPoll$ = singleLoad$.pipe(
const freshPoll$ = defer(() => singleLoad$.pipe(
decay({ initialInterval, maxInterval }),
repeat(),
);
repeat()
));
// history, tools routes all refresh
// exclude our own polling url though
const routes = [/api\/(history|tools|histories)/];
const methods = ["POST", "PUT", "DELETE"]
const methods = ["POST", "PUT", "DELETE"];
const resetPoll$ = monitorXHR({ methods, routes });
// resets re-subscribe to freshPoll$ starting the decay over again
@@ -40,5 +40,5 @@ export const loadContents = (cfg = {}) => {
);
return disablePoll ? singleLoad$ : poll$;
})
}
});
};
+4 -1
View File
@@ -2,6 +2,8 @@
import { of } from "rxjs";
import { mergeMap, delay } from "rxjs/operators";
let decayCounter = 0;
// prettier-ignore
export const decay = (cfg = {}) => {
const {
@@ -15,12 +17,13 @@ export const decay = (cfg = {}) => {
}
let counter = 0;
decayCounter++;
return mergeMap(val => {
let waitTime = Math.floor(initialInterval * Math.exp(lambda * counter++));
waitTime = Math.max(waitTime, initialInterval);
waitTime = Math.min(waitTime, maxInterval);
// console.log("decay time", waitTime);
console.log("decay time", decayCounter, waitTime);
return of(val).pipe(delay(waitTime))
});
}