Vue Polling - Code sycn with fixes from Shipping Portal (dillon/51-vue-polling-experimental-1)

This commit is contained in:
Dillon Ngo
2023-12-19 20:32:24 +08:00
parent 3a1e9ac929
commit 3a8124817d
@@ -135,15 +135,34 @@
this.isPolling = false;
// this.isLoading = false;
},
startPolling(jobId) {
// this.fetchJobResult(jobId); // Start immediately
this.pollingInterval = setInterval(() => {
startPolling(jobId, maxAttempts = 3) {
let attempts = 0;
const pollJobResult = () => {
if (this.isPolling) {
return;
}
this.isPolling = true;
this.fetchJobResult(jobId); // Replace with the actual job ID
}, 10000); // Poll every 5 seconds
attempts++;
if (attempts > maxAttempts) {
clearInterval(this.pollingInterval);
this.pollingInterval = null;
this.isPolling = false;
this.isLoading = false;
console.log(`Reached maximum attempts (${maxAttempts}). Polling stopped.`);
return;
}
this.fetchJobResult(jobId);
};
// Initial call
// pollJobResult();
// Set up polling interval
this.pollingInterval = setInterval(pollJobResult, 10000);
},
stopPolling() {
clearInterval(this.pollingInterval);