This commit is contained in:
2020-08-03 23:42:48 +00:00
parent 0af53836f1
commit 33303f2e34
2 changed files with 27 additions and 46 deletions

View File

@@ -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 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: read only version of duration, datetime, date, time, currency
todo: does Duplicate code really duplicate the tags? todo: does Duplicate code really duplicate the tags?

View File

@@ -1,54 +1,42 @@
/* xeslint-disable */ /* xeslint-disable */
let keepPolling = false; let keepChecking = false;
const DEFAULT_POLLING_INTERVAL = 60000; 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 { export default {
async startPolling() { async startPolling() {
keepPolling = true; if (keepChecking == true) {
return;
}
keepChecking = true;
let pollingInterval = window.$gz.dev ? 20000 : DEFAULT_POLLING_INTERVAL; let pollingInterval = window.$gz.dev ? 20000 : DEFAULT_POLLING_INTERVAL;
try { let status = null;
while (keepPolling == true) { while (keepChecking == true) {
let status = await window.$gz.api.get("notify/new-count"); try {
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;
await window.$gz.util.sleepAsync(pollingInterval); await window.$gz.util.sleepAsync(pollingInterval);
} if (keepChecking && window.$gz.store.state.authenticated) {
} catch (error) { status = await window.$gz.api.get("notify/new-count");
pollingInterval *= 1.5; if (status.error) {
if (pollingInterval > MAX_POLLING_INTERVAL) { throw status.error;
pollingInterval = MAX_POLLING_INTERVAL; } else {
} window.$gz.store.commit("setNewNotificationCount", status.data);
//success so go to default in case it was changed by an error
//could be a expected issue such as server closed for maintenance pollingInterval = window.$gz.dev ? 20000 : DEFAULT_POLLING_INTERVAL;
//so no need to freak out if that's the case }
if (error.code) { } else {
//is it a normal issue? keepChecking = false;
if (error.code == 2001) { }
return; } 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() { stopPolling() {
keepPolling = false; keepChecking = false;
} }
}; };