This commit is contained in:
2020-07-07 23:12:34 +00:00
parent 783cc19502
commit ca3fb50058
3 changed files with 22 additions and 9 deletions

View File

@@ -1,23 +1,29 @@
/* xeslint-disable */
let keepPolling = false;
const DEFAULT_POLLING_INTERVAL = 10000;
const MAX_POLLING_INTERVAL = 15 * 60 * 1000; //15 minutes maximum wait time
export default {
async startPolling() {
console.log("notifypoll::starting polling");
keepPolling = true;
let pollingInterval = DEFAULT_POLLING_INTERVAL;
try {
while (keepPolling == true) {
let status = await window.$gz.api.get("notify/new-count");
if (status.error) {
throw status.error;
}
console.log("notifypoll::new count ", status);
// window.$gz.store.commit("setNotifyNewCount", status.data);
await window.$gz.util.sleepAsync(10000);
window.$gz.store.commit("setNewNotificationCount", status.data);
//success so go to default in case it was changed by an error
pollingInterval = DEFAULT_POLLING_INTERVAL;
await window.$gz.util.sleepAsync(pollingInterval);
}
} catch (error) {
keepPolling = false;
pollingInterval *= 1.5;
if (pollingInterval > MAX_POLLING_INTERVAL) {
pollingInterval = MAX_POLLING_INTERVAL;
}
window.$gz.errorHandler.handleGeneralError(
"Error checking for notifications",
"notifypoll",
@@ -33,6 +39,5 @@ export default {
},
stopPolling() {
keepPolling = false;
console.log("notifypoll::stopping polling");
}
};