mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
Removed superagent dependency (#10535)
no issue - Migrated default scheduling adapter to use Got via the request proxy - SchedulingDefault is the only module that was using superagent so removed it as a dependency
This commit is contained in:
parent
01b03f7a1a
commit
42c472feff
@ -1,9 +1,9 @@
|
||||
const util = require('util'),
|
||||
moment = require('moment'),
|
||||
request = require('superagent'),
|
||||
debug = require('ghost-ignition').debug('scheduling-default'),
|
||||
SchedulingBase = require('./SchedulingBase'),
|
||||
common = require('../../lib/common');
|
||||
const util = require('util');
|
||||
const moment = require('moment');
|
||||
const debug = require('ghost-ignition').debug('scheduling-default');
|
||||
const SchedulingBase = require('./SchedulingBase');
|
||||
const common = require('../../lib/common');
|
||||
const request = require('../../lib/request');
|
||||
|
||||
/**
|
||||
* allJobs is a sorted list by time attribute
|
||||
@ -197,61 +197,60 @@ SchedulingDefault.prototype._execute = function (jobs) {
|
||||
* - if we detect to publish a post in the past (case blog is down), we add a force flag
|
||||
*/
|
||||
SchedulingDefault.prototype._pingUrl = function (object) {
|
||||
debug('Ping url', object.url, moment().format('YYYY-MM-DD HH:mm:ss'), moment(object.time).format('YYYY-MM-DD HH:mm:ss'));
|
||||
|
||||
let timeout;
|
||||
const {url, time} = object;
|
||||
const httpMethod = object.extra ? object.extra.httpMethod : 'PUT',
|
||||
tries = object.tries || 0,
|
||||
requestTimeout = object.extra ? object.extra.timeoutInMS : 1000 * 5,
|
||||
maxTries = 30,
|
||||
req = request[httpMethod.toLowerCase()](url),
|
||||
self = this;
|
||||
|
||||
debug('Ping url', url, moment().format('YYYY-MM-DD HH:mm:ss'), moment(time).format('YYYY-MM-DD HH:mm:ss'));
|
||||
|
||||
const httpMethod = object.extra ? object.extra.httpMethod : 'PUT';
|
||||
const tries = object.tries || 0;
|
||||
const requestTimeout = object.extra ? object.extra.timeoutInMS : 1000 * 5;
|
||||
const maxTries = 30;
|
||||
|
||||
const options = {
|
||||
timeout: requestTimeout,
|
||||
method: httpMethod.toLowerCase(),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
if (moment(time).isBefore(moment())) {
|
||||
if (httpMethod === 'GET') {
|
||||
req.query('force=true');
|
||||
// @todo: rename to searchParams when updating to Got v10
|
||||
options.query = 'force=true';
|
||||
} else {
|
||||
req.send({
|
||||
force: true
|
||||
});
|
||||
options.body = JSON.stringify({force: true});
|
||||
}
|
||||
}
|
||||
|
||||
req.timeout({
|
||||
response: requestTimeout
|
||||
});
|
||||
return request(url, options).catch((err) => {
|
||||
const {statusCode} = err;
|
||||
|
||||
req.end(function (err, response) {
|
||||
if (err) {
|
||||
// CASE: post/page was deleted already
|
||||
if (response && response.status === 404) {
|
||||
return;
|
||||
}
|
||||
// CASE: post/page was deleted already
|
||||
if (statusCode === 404) {
|
||||
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);
|
||||
|
||||
common.logging.error(new common.errors.GhostError({
|
||||
err,
|
||||
context: 'Retrying...',
|
||||
level: 'normal'
|
||||
}));
|
||||
|
||||
return;
|
||||
}
|
||||
// CASE: blog is in maintenance mode, retry
|
||||
if (statusCode === 503 && tries < maxTries) {
|
||||
setTimeout(() => {
|
||||
object.tries = tries + 1;
|
||||
this._pingUrl(object);
|
||||
}, this.retryTimeoutInMs);
|
||||
|
||||
common.logging.error(new common.errors.GhostError({
|
||||
err,
|
||||
level: 'critical'
|
||||
context: 'Retrying...',
|
||||
level: 'normal'
|
||||
}));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
common.logging.error(new common.errors.GhostError({
|
||||
err,
|
||||
level: 'critical'
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -224,16 +224,11 @@ describe('Scheduling Default Adapter', function () {
|
||||
extra: {
|
||||
httpMethod: 'GET'
|
||||
}
|
||||
}).then(() => {
|
||||
wasPinged.should.be.true();
|
||||
should.not.exist(reqQuery.force);
|
||||
server.close(done);
|
||||
});
|
||||
|
||||
(function retry() {
|
||||
if (wasPinged) {
|
||||
should.not.exist(reqQuery.force);
|
||||
return server.close(done);
|
||||
}
|
||||
|
||||
setTimeout(retry, 100);
|
||||
})();
|
||||
});
|
||||
|
||||
it('pingUrl (PUT, and detect publish in the past)', function (done) {
|
||||
@ -258,16 +253,11 @@ describe('Scheduling Default Adapter', function () {
|
||||
extra: {
|
||||
httpMethod: 'PUT'
|
||||
}
|
||||
}).then(() => {
|
||||
wasPinged.should.be.true();
|
||||
should.exist(reqBody.force);
|
||||
server.close(done);
|
||||
});
|
||||
|
||||
(function retry() {
|
||||
if (wasPinged) {
|
||||
should.exist(reqBody.force);
|
||||
return server.close(done);
|
||||
}
|
||||
|
||||
setTimeout(retry, 100);
|
||||
})();
|
||||
});
|
||||
|
||||
it('pingUrl (GET, and detect publish in the past)', function (done) {
|
||||
@ -290,16 +280,11 @@ describe('Scheduling Default Adapter', function () {
|
||||
extra: {
|
||||
httpMethod: 'GET'
|
||||
}
|
||||
}).then(() => {
|
||||
wasPinged.should.be.true();
|
||||
should.exist(reqQuery.force);
|
||||
server.close(done);
|
||||
});
|
||||
|
||||
(function retry() {
|
||||
if (wasPinged) {
|
||||
should.exist(reqQuery.force);
|
||||
return server.close(done);
|
||||
}
|
||||
|
||||
setTimeout(retry, 100);
|
||||
})();
|
||||
});
|
||||
|
||||
it('pingUrl, but blog returns 503', function (done) {
|
||||
|
@ -106,7 +106,6 @@
|
||||
"simple-dom": "0.3.2",
|
||||
"simple-html-tokenizer": "0.5.7",
|
||||
"stripe": "^6.22.0",
|
||||
"superagent": "4.1.0",
|
||||
"unidecode": "0.1.8",
|
||||
"uuid": "3.3.2",
|
||||
"validator": "6.3.0",
|
||||
|
24
yarn.lock
24
yarn.lock
@ -1157,7 +1157,7 @@ cookie@0.3.1:
|
||||
version "0.3.1"
|
||||
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
|
||||
|
||||
cookiejar@^2.1.0, cookiejar@^2.1.2:
|
||||
cookiejar@^2.1.0:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.2.tgz#dd8a235530752f988f9a0844f3fc589e3111125c"
|
||||
|
||||
@ -2214,7 +2214,7 @@ forever-agent@~0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
|
||||
|
||||
form-data@^2.3.1, form-data@^2.3.3, form-data@~2.3.2:
|
||||
form-data@^2.3.1, form-data@~2.3.2:
|
||||
version "2.3.3"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
|
||||
dependencies:
|
||||
@ -4064,10 +4064,6 @@ mime@^1.4.1:
|
||||
version "1.6.0"
|
||||
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
|
||||
|
||||
mime@^2.4.0:
|
||||
version "2.4.0"
|
||||
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.0.tgz#e051fd881358585f3279df333fe694da0bcffdd6"
|
||||
|
||||
mime@~1.2.11:
|
||||
version "1.2.11"
|
||||
resolved "https://registry.yarnpkg.com/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10"
|
||||
@ -5266,7 +5262,7 @@ qs@6.5.2, qs@~6.5.1, qs@~6.5.2:
|
||||
version "6.5.2"
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
|
||||
|
||||
qs@^6.4.0, qs@^6.5.1, qs@^6.6.0:
|
||||
qs@^6.4.0, qs@^6.5.1:
|
||||
version "6.6.0"
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.6.0.tgz#a99c0f69a8d26bf7ef012f871cdabb0aee4424c2"
|
||||
|
||||
@ -6140,20 +6136,6 @@ stripe@^6.22.0:
|
||||
qs "~6.5.1"
|
||||
safe-buffer "^5.1.1"
|
||||
|
||||
superagent@4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/superagent/-/superagent-4.1.0.tgz#c465c2de41df2b8d05c165cbe403e280790cdfd5"
|
||||
dependencies:
|
||||
component-emitter "^1.2.0"
|
||||
cookiejar "^2.1.2"
|
||||
debug "^4.1.0"
|
||||
form-data "^2.3.3"
|
||||
formidable "^1.2.0"
|
||||
methods "^1.1.1"
|
||||
mime "^2.4.0"
|
||||
qs "^6.6.0"
|
||||
readable-stream "^3.0.6"
|
||||
|
||||
superagent@^3.8.3:
|
||||
version "3.8.3"
|
||||
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.8.3.tgz#460ea0dbdb7d5b11bc4f78deba565f86a178e128"
|
||||
|
Loading…
Reference in New Issue
Block a user