This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user