fixes for polling restore

This commit is contained in:
Andy Miller
2025-10-18 18:26:38 -06:00
parent 06632728f0
commit c4fb1f7fd8
2 changed files with 65 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ class RestoreManager {
constructor() {
this.job = null;
this.pollTimer = null;
this.pollFailures = 0;
$(document).on('click', '[data-restore-snapshot]', (event) => {
event.preventDefault();
@@ -62,6 +63,7 @@ class RestoreManager {
id: jobId,
snapshot,
};
this.pollFailures = 0;
const runningMessage = translations.PLUGIN_ADMIN?.RESTORE_GRAV_RUNNING
? translations.PLUGIN_ADMIN.RESTORE_GRAV_RUNNING.replace('%s', snapshot)
@@ -89,7 +91,12 @@ class RestoreManager {
}
const jobId = this.job.id;
let handled = false;
request(`${urls.status}?job=${encodeURIComponent(jobId)}`, { silentErrors: true }, (response) => {
handled = true;
this.pollFailures = 0;
if (!response || response.status !== 'success') {
this.schedulePoll();
return;
@@ -129,8 +136,36 @@ class RestoreManager {
}
this.schedulePoll();
}).then(() => {
if (!handled) {
this.handleSilentFailure();
}
});
}
handleSilentFailure() {
if (!this.job) {
return;
}
this.pollFailures += 1;
const snapshot = this.job.snapshot || '';
if (this.pollFailures >= 3) {
const message = snapshot
? `Snapshot ${snapshot} restore is completing. Reloading...`
: 'Snapshot restore is completing. Reloading...';
toastr.info(message);
this.job = null;
this.clearPoll();
setTimeout(() => window.location.reload(), 1500);
return;
}
const delay = Math.min(5000, 1200 * this.pollFailures);
this.schedulePoll(delay);
}
}
// Initialize restore manager when tools view loads.