mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-03 03:46:30 +01:00
fixes for polling restore
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user