mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 02:44:33 +03:00
Merge pull request #6990 from kirrg001/improvement/503-for-scheduling
post-scheduling: 503 retry logic for default adapter
This commit is contained in:
commit
7d8e01b14e
@ -13,6 +13,7 @@ function SchedulingDefault(options) {
|
|||||||
this.runTimeoutInMs = 1000 * 60 * 5;
|
this.runTimeoutInMs = 1000 * 60 * 5;
|
||||||
this.offsetInMinutes = 10;
|
this.offsetInMinutes = 10;
|
||||||
this.beforePingInMs = -50;
|
this.beforePingInMs = -50;
|
||||||
|
this.retryTimeoutInMs = 1000 * 5;
|
||||||
|
|
||||||
this.allJobs = {};
|
this.allJobs = {};
|
||||||
this.deletedJobs = {};
|
this.deletedJobs = {};
|
||||||
@ -158,14 +159,16 @@ SchedulingDefault.prototype._execute = function (jobs) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if we detect to publish a post in the past (case blog is down)
|
* - if we detect to publish a post in the past (case blog is down), we add a force flag
|
||||||
* we add a force flag
|
|
||||||
*/
|
*/
|
||||||
SchedulingDefault.prototype._pingUrl = function (object) {
|
SchedulingDefault.prototype._pingUrl = function (object) {
|
||||||
var url = object.url,
|
var url = object.url,
|
||||||
time = object.time,
|
time = object.time,
|
||||||
httpMethod = object.extra.httpMethod,
|
httpMethod = object.extra.httpMethod,
|
||||||
req = request[httpMethod.toLowerCase()](url);
|
tries = object.tries || 0,
|
||||||
|
maxTries = 30,
|
||||||
|
req = request[httpMethod.toLowerCase()](url),
|
||||||
|
self = this, timeout;
|
||||||
|
|
||||||
if (moment(time).isBefore(moment())) {
|
if (moment(time).isBefore(moment())) {
|
||||||
if (httpMethod === 'GET') {
|
if (httpMethod === 'GET') {
|
||||||
@ -184,6 +187,16 @@ SchedulingDefault.prototype._pingUrl = function (object) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CASE: blog is in maintenance mode, retry
|
||||||
|
if (response && response.status === 503 && tries < maxTries) {
|
||||||
|
timeout = setTimeout(function pingAgain() {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
|
||||||
|
object.tries = tries + 1;
|
||||||
|
self._pingUrl(object);
|
||||||
|
}, self.retryTimeoutInMs);
|
||||||
|
}
|
||||||
|
|
||||||
errors.logError(err);
|
errors.logError(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -282,5 +282,47 @@ describe('Scheduling Default Adapter', function () {
|
|||||||
setTimeout(retry, 100);
|
setTimeout(retry, 100);
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('pingUrl, but blog returns 503', function (done) {
|
||||||
|
var app = express(),
|
||||||
|
server = http.createServer(app),
|
||||||
|
returned500Count = 0,
|
||||||
|
returned200 = false,
|
||||||
|
reqBody;
|
||||||
|
|
||||||
|
scope.adapter.retryTimeoutInMs = 200;
|
||||||
|
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
app.put('/ping', function (req, res) {
|
||||||
|
reqBody = req.body;
|
||||||
|
|
||||||
|
if (returned500Count === 5) {
|
||||||
|
returned200 = true;
|
||||||
|
return res.sendStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
returned500Count = returned500Count + 1;
|
||||||
|
res.sendStatus(503);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(1111);
|
||||||
|
|
||||||
|
scope.adapter._pingUrl({
|
||||||
|
url: 'http://localhost:1111/ping',
|
||||||
|
time: moment().valueOf(),
|
||||||
|
extra: {
|
||||||
|
httpMethod: 'PUT'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
(function retry() {
|
||||||
|
if (returned200) {
|
||||||
|
should.exist(reqBody.force);
|
||||||
|
return server.close(done);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(retry, 100);
|
||||||
|
})();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user