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
=-=-=-=-
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?

View File

@@ -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;
}
};