mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-26 00:36:31 +02: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.
|
||||
|
||||
30
themes/grav/js/admin.min.js
vendored
30
themes/grav/js/admin.min.js
vendored
@@ -10988,6 +10988,7 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
restore_classCallCheck(this, RestoreManager);
|
||||
this.job = null;
|
||||
this.pollTimer = null;
|
||||
this.pollFailures = 0;
|
||||
external_jQuery_default()(document).on('click', '[data-restore-snapshot]', function (event) {
|
||||
event.preventDefault();
|
||||
var button = external_jQuery_default()(event.currentTarget);
|
||||
@@ -11037,6 +11038,7 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
id: jobId,
|
||||
snapshot: snapshot
|
||||
};
|
||||
_this2.pollFailures = 0;
|
||||
var runningMessage = (_translations$PLUGIN_4 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_4 !== void 0 && _translations$PLUGIN_4.RESTORE_GRAV_RUNNING ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_RUNNING.replace('%s', snapshot) : "Restoring snapshot ".concat(snapshot, "...");
|
||||
utils_toastr.info(runningMessage);
|
||||
_this2.schedulePoll();
|
||||
@@ -11068,9 +11070,12 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
return;
|
||||
}
|
||||
var jobId = this.job.id;
|
||||
var handled = false;
|
||||
utils_request("".concat(urls.status, "?job=").concat(encodeURIComponent(jobId)), {
|
||||
silentErrors: true
|
||||
}, function (response) {
|
||||
handled = true;
|
||||
_this4.pollFailures = 0;
|
||||
if (!response || response.status !== 'success') {
|
||||
_this4.schedulePoll();
|
||||
return;
|
||||
@@ -11109,8 +11114,33 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
return;
|
||||
}
|
||||
_this4.schedulePoll();
|
||||
}).then(function () {
|
||||
if (!handled) {
|
||||
_this4.handleSilentFailure();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "handleSilentFailure",
|
||||
value: function handleSilentFailure() {
|
||||
if (!this.job) {
|
||||
return;
|
||||
}
|
||||
this.pollFailures += 1;
|
||||
var snapshot = this.job.snapshot || '';
|
||||
if (this.pollFailures >= 3) {
|
||||
var message = snapshot ? "Snapshot ".concat(snapshot, " restore is completing. Reloading...") : 'Snapshot restore is completing. Reloading...';
|
||||
utils_toastr.info(message);
|
||||
this.job = null;
|
||||
this.clearPoll();
|
||||
setTimeout(function () {
|
||||
return window.location.reload();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
var delay = Math.min(5000, 1200 * this.pollFailures);
|
||||
this.schedulePoll(delay);
|
||||
}
|
||||
}]);
|
||||
}(); // Initialize restore manager when tools view loads.
|
||||
external_jQuery_default()(document).ready(function () {
|
||||
|
||||
Reference in New Issue
Block a user