From 33303f2e342e231d382219d99d947812150a40fa Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 3 Aug 2020 23:42:48 +0000 Subject: [PATCH] --- ayanova/devdocs/todo.txt | 7 ---- ayanova/src/api/notifypoll.js | 66 ++++++++++++++--------------------- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index fce8e59b..c3328f40 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -3,13 +3,6 @@ PRIORITY - ALWAYS Lowest level stuff first, i.e. TODO at server, api route changes etc then back here in order lowest level first as affects the most stuff exponentially so best to do it early =-=-=-=- -todo: erase database missing subscriptions? - Check and see what's missing, I just got 100 notifications about widgets made, I think because I picked generate data and had an old subscription still - -todo: Test server down while polling in release mode, does it recover when server starts again or...? - consider adding a trigger check in api methods or router or somewhere that gets triggered by user regularly - then can check if it's running polling or not and restart if it is, particularly after a successful api call which says server is up and contactable - todo: read only version of duration, datetime, date, time, currency todo: does Duplicate code really duplicate the tags? diff --git a/ayanova/src/api/notifypoll.js b/ayanova/src/api/notifypoll.js index e6e9c3ed..a75929bb 100644 --- a/ayanova/src/api/notifypoll.js +++ b/ayanova/src/api/notifypoll.js @@ -1,54 +1,42 @@ /* xeslint-disable */ -let keepPolling = false; +let keepChecking = false; const DEFAULT_POLLING_INTERVAL = 60000; -const MAX_POLLING_INTERVAL = 15 * 60 * 1000; //15 minutes maximum wait time +//const DEFAULT_POLLING_INTERVAL = 5000; +const MAX_POLLING_INTERVAL = 10 * 60 * 1000; //10 minutes maximum wait time export default { async startPolling() { - keepPolling = true; + if (keepChecking == true) { + return; + } + keepChecking = true; let pollingInterval = window.$gz.dev ? 20000 : DEFAULT_POLLING_INTERVAL; - try { - while (keepPolling == true) { - let status = await window.$gz.api.get("notify/new-count"); - if (status.error) { - throw status.error; - } - window.$gz.store.commit("setNewNotificationCount", status.data); - //success so go to default in case it was changed by an error - pollingInterval = window.$gz.dev ? 20000 : DEFAULT_POLLING_INTERVAL; + let status = null; + while (keepChecking == true) { + try { await window.$gz.util.sleepAsync(pollingInterval); - } - } catch (error) { - pollingInterval *= 1.5; - if (pollingInterval > MAX_POLLING_INTERVAL) { - pollingInterval = MAX_POLLING_INTERVAL; - } - - //could be a expected issue such as server closed for maintenance - //so no need to freak out if that's the case - if (error.code) { - //is it a normal issue? - if (error.code == 2001) { - return; + if (keepChecking && window.$gz.store.state.authenticated) { + status = await window.$gz.api.get("notify/new-count"); + if (status.error) { + throw status.error; + } else { + window.$gz.store.commit("setNewNotificationCount", status.data); + //success so go to default in case it was changed by an error + pollingInterval = window.$gz.dev ? 20000 : DEFAULT_POLLING_INTERVAL; + } + } else { + keepChecking = false; + } + } catch (error) { + pollingInterval *= 1.5; + if (pollingInterval > MAX_POLLING_INTERVAL) { + pollingInterval = MAX_POLLING_INTERVAL; } } - //Nope, totally unexpected, alert the user - window.$gz.errorHandler.handleGeneralError( - "Error checking for notifications", - "notifypoll", - null, - null, - error - ); - //this was annoying. Maybe just turn the bell red when it fails and then color it again when it's ok?! - // window.$gz.eventBus.$emit( - // "notify-error", - // "Error checking for notifications, see about->log for details; log out and back in again to reset" - // ); } }, stopPolling() { - keepPolling = false; + keepChecking = false; } };