mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03: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:
parent
53dbbf33a5
commit
766de0d475
@ -13,7 +13,7 @@ import {get} from '@ember/object';
|
||||
import {htmlSafe} from '@ember/template';
|
||||
import {isBlank} from '@ember/utils';
|
||||
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 {isVersionMismatchError} from 'ghost-admin/services/ajax';
|
||||
import {inject as service} from '@ember/service';
|
||||
@ -604,11 +604,13 @@ export default Controller.extend({
|
||||
let {post} = this;
|
||||
|
||||
// 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 maxAttempts = 6;
|
||||
let startTime = moment();
|
||||
const maxAttempts = 6;
|
||||
const startTime = moment();
|
||||
const retryErrorChecks = [isServerUnreachableError, isMaintenanceError];
|
||||
let success = false;
|
||||
|
||||
while (attempts < maxAttempts && !success) {
|
||||
try {
|
||||
yield post.save(options);
|
||||
@ -622,7 +624,7 @@ export default Controller.extend({
|
||||
} catch (error) {
|
||||
attempts += 1;
|
||||
|
||||
if (isServerUnreachableError(error) && attempts < maxAttempts) {
|
||||
if (retryErrorChecks.some(check => check(error)) && attempts < maxAttempts) {
|
||||
yield timeout(5 * 1000);
|
||||
} else if (isServerUnreachableError(error)) {
|
||||
const [prevStatus, newStatus] = this.post.changedAttributes().status || [this.post.status, this.post.status];
|
||||
|
Loading…
Reference in New Issue
Block a user