0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Added automatic retry of failed editor saves when Ghost is in maintenance mode

no issue

- when Ghost is in maintenance mode after an upgrade we know it will come back shortly so automatically retrying the save in the same way we do for "server unreachable" errors provides a smoother experience compared to halting and showing a red alert bar
This commit is contained in:
Kevin Ansfield 2021-06-28 15:33:40 +01:00
parent 53dbbf33a5
commit 766de0d475

View file

@ -13,7 +13,7 @@ import {get} from '@ember/object';
import {htmlSafe} from '@ember/template'; import {htmlSafe} from '@ember/template';
import {isBlank} from '@ember/utils'; import {isBlank} from '@ember/utils';
import {isArray as isEmberArray} from '@ember/array'; import {isArray as isEmberArray} from '@ember/array';
import {isHostLimitError, isServerUnreachableError} from 'ghost-admin/services/ajax'; import {isHostLimitError, isMaintenanceError, isServerUnreachableError} from 'ghost-admin/services/ajax';
import {isInvalidError} from 'ember-ajax/errors'; import {isInvalidError} from 'ember-ajax/errors';
import {isVersionMismatchError} from 'ghost-admin/services/ajax'; import {isVersionMismatchError} from 'ghost-admin/services/ajax';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
@ -604,11 +604,13 @@ export default Controller.extend({
let {post} = this; let {post} = this;
// retry save every 5 seconds for a total of 30secs // retry save every 5 seconds for a total of 30secs
// only retry if we get a ServerUnreachable error (code 0) from the browser // only retry if we get a ServerUnreachable error (code 0) from the browser or a MaintenanceError from Ghost
let attempts = 0; let attempts = 0;
let maxAttempts = 6; const maxAttempts = 6;
let startTime = moment(); const startTime = moment();
const retryErrorChecks = [isServerUnreachableError, isMaintenanceError];
let success = false; let success = false;
while (attempts < maxAttempts && !success) { while (attempts < maxAttempts && !success) {
try { try {
yield post.save(options); yield post.save(options);
@ -622,7 +624,7 @@ export default Controller.extend({
} catch (error) { } catch (error) {
attempts += 1; attempts += 1;
if (isServerUnreachableError(error) && attempts < maxAttempts) { if (retryErrorChecks.some(check => check(error)) && attempts < maxAttempts) {
yield timeout(5 * 1000); yield timeout(5 * 1000);
} else if (isServerUnreachableError(error)) { } else if (isServerUnreachableError(error)) {
const [prevStatus, newStatus] = this.post.changedAttributes().status || [this.post.status, this.post.status]; const [prevStatus, newStatus] = this.post.changedAttributes().status || [this.post.status, this.post.status];