mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Added support for jobs defined as modules
no issue - These changes should allow easy testing of scheduled jobs and provide an implementation example for future jobs within Ghost - Added experimental support to run jobs based on functions defined in modules - Extendeded testmode "schedule" endpoint with an optional job name parameter which picks up job from "jobs" folder - Adjusted scheduleJob method use and passed "schedule" as first parameter - Bumped job-manager version to allow for all new functionality
This commit is contained in:
parent
d6505899a7
commit
5b6fe31002
@ -1,3 +1,4 @@
|
|||||||
|
const path = require('path');
|
||||||
const logging = require('../../../../shared/logging');
|
const logging = require('../../../../shared/logging');
|
||||||
const express = require('../../../../shared/express');
|
const express = require('../../../../shared/express');
|
||||||
const jobService = require('../../../services/jobs');
|
const jobService = require('../../../services/jobs');
|
||||||
@ -40,24 +41,29 @@ module.exports = function testRoutes() {
|
|||||||
res.sendStatus(202);
|
res.sendStatus(202);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/schedule/:schedule', (req, res) => {
|
router.get('/schedule/:schedule/:name*?', (req, res) => {
|
||||||
if (!req.params.schedule) {
|
if (!req.params.schedule) {
|
||||||
return res.sendStatus(400, 'schedule parameter cannot be mepty');
|
return res.sendStatus(400, 'schedule parameter cannot be mepty');
|
||||||
}
|
}
|
||||||
|
|
||||||
const schedule = req.params.schedule;
|
const schedule = req.params.schedule;
|
||||||
logging.info('Achedule a Job with schedule of:', schedule);
|
logging.info('Achedule a Job with schedule of:', schedule, req.params.name);
|
||||||
|
|
||||||
jobService.scheduleJob(() => {
|
if (req.params.name) {
|
||||||
return new Promise((resolve) => {
|
const jobPath = path.resolve(__dirname, 'jobs', req.params.name);
|
||||||
logging.info('Start scheduled Job');
|
jobService.scheduleJob(schedule, jobPath);
|
||||||
|
} else {
|
||||||
|
jobService.scheduleJob(schedule, () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
logging.info('Start scheduled Job');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
logging.info('End scheduled Job run', schedule);
|
logging.info('End scheduled Job run', schedule);
|
||||||
resolve();
|
resolve();
|
||||||
}, 20 * 1000);
|
}, 20 * 1000);
|
||||||
});
|
});
|
||||||
}, {}, schedule);
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
res.sendStatus(202);
|
res.sendStatus(202);
|
||||||
});
|
});
|
||||||
|
17
core/server/web/api/testmode/jobs/say-hello.js
Normal file
17
core/server/web/api/testmode/jobs/say-hello.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
const logging = require('../../../../../shared/logging');
|
||||||
|
|
||||||
|
const helloJob = () => {
|
||||||
|
logging.info('Starting hello job');
|
||||||
|
|
||||||
|
logging.info('Gonna say "hi" in 5 seconds');
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
logging.info('hi!');
|
||||||
|
logging.info('Ending hello job run.');
|
||||||
|
resolve();
|
||||||
|
}, 5 * 1000);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = helloJob;
|
@ -49,7 +49,7 @@
|
|||||||
"@tryghost/errors": "0.2.5",
|
"@tryghost/errors": "0.2.5",
|
||||||
"@tryghost/helpers": "1.1.34",
|
"@tryghost/helpers": "1.1.34",
|
||||||
"@tryghost/image-transform": "1.0.3",
|
"@tryghost/image-transform": "1.0.3",
|
||||||
"@tryghost/job-manager": "0.1.2",
|
"@tryghost/job-manager": "0.2.0",
|
||||||
"@tryghost/kg-card-factory": "2.1.4",
|
"@tryghost/kg-card-factory": "2.1.4",
|
||||||
"@tryghost/kg-default-atoms": "2.0.2",
|
"@tryghost/kg-default-atoms": "2.0.2",
|
||||||
"@tryghost/kg-default-cards": "3.0.1",
|
"@tryghost/kg-default-cards": "3.0.1",
|
||||||
|
75
yarn.lock
75
yarn.lock
@ -23,6 +23,13 @@
|
|||||||
chalk "^2.0.0"
|
chalk "^2.0.0"
|
||||||
js-tokens "^4.0.0"
|
js-tokens "^4.0.0"
|
||||||
|
|
||||||
|
"@babel/runtime@^7.10.5":
|
||||||
|
version "7.12.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
|
||||||
|
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
|
||||||
|
dependencies:
|
||||||
|
regenerator-runtime "^0.13.4"
|
||||||
|
|
||||||
"@breejs/later@4.0.2":
|
"@breejs/later@4.0.2":
|
||||||
version "4.0.2"
|
version "4.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/@breejs/later/-/later-4.0.2.tgz#38c85cc98b717c7a196f87238090adaea01f8c9e"
|
resolved "https://registry.yarnpkg.com/@breejs/later/-/later-4.0.2.tgz#38c85cc98b717c7a196f87238090adaea01f8c9e"
|
||||||
@ -442,13 +449,13 @@
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
sharp "0.25.4"
|
sharp "0.25.4"
|
||||||
|
|
||||||
"@tryghost/job-manager@0.1.2":
|
"@tryghost/job-manager@0.2.0":
|
||||||
version "0.1.2"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.1.2.tgz#f22c1a574423567cf028c45ea2fdf29613a073ab"
|
resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.2.0.tgz#5c6949c89966b712a12b38e95ffaa076281a9471"
|
||||||
integrity sha512-P3NI7mEA6zDy5FVR9woW10HNmdQbi5SmNM0gG04jwupNmA5RaTGwzBEVPMdws73gCv8psjsnRcEDcOQ1fuPOaw==
|
integrity sha512-Tylxoy0SLrnN/iuN/uBc5EB67lhsB3IFDzh0ug5HlES559OW0byYKMwXBxuVA/Tkb8j1eF6nE81GjEqhdi6+FA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@breejs/later" "4.0.2"
|
"@breejs/later" "4.0.2"
|
||||||
cron-parser "2.17.0"
|
cron-validate "1.4.0"
|
||||||
fastq "1.9.0"
|
fastq "1.9.0"
|
||||||
p-wait-for "3.1.0"
|
p-wait-for "3.1.0"
|
||||||
|
|
||||||
@ -2193,13 +2200,12 @@ create-error@~0.3.1:
|
|||||||
resolved "https://registry.yarnpkg.com/create-error/-/create-error-0.3.1.tgz#69810245a629e654432bf04377360003a5351a23"
|
resolved "https://registry.yarnpkg.com/create-error/-/create-error-0.3.1.tgz#69810245a629e654432bf04377360003a5351a23"
|
||||||
integrity sha1-aYECRaYp5lRDK/BDdzYAA6U1GiM=
|
integrity sha1-aYECRaYp5lRDK/BDdzYAA6U1GiM=
|
||||||
|
|
||||||
cron-parser@2.17.0:
|
cron-validate@1.4.0:
|
||||||
version "2.17.0"
|
version "1.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/cron-parser/-/cron-parser-2.17.0.tgz#5707421a7e0a73ee74675d1c032a2f14123f2cf8"
|
resolved "https://registry.yarnpkg.com/cron-validate/-/cron-validate-1.4.0.tgz#aaf5c789db5226ad82b8168ec7654023984c27b3"
|
||||||
integrity sha512-oTmzVEwlurRe51HqTm4afshVr8Rkxy9kFiWxh5e6SmrY2o9NDYU4S6SduanBZYXLgkLy0skA98y7/tztW/DmjQ==
|
integrity sha512-z4Mik62Wdvgn1WC9OCGdwxTYO6TCjasTw3SAYsVq0tfArYh6Zg7bbgGVVNBiNAcnnxXsdnBj4AatkYunntaT9A==
|
||||||
dependencies:
|
dependencies:
|
||||||
is-nan "^1.3.0"
|
yup "0.29.3"
|
||||||
moment-timezone "^0.5.31"
|
|
||||||
|
|
||||||
cross-spawn@^5.0.1:
|
cross-spawn@^5.0.1:
|
||||||
version "5.1.0"
|
version "5.1.0"
|
||||||
@ -3615,6 +3621,11 @@ flatted@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
|
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
|
||||||
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==
|
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==
|
||||||
|
|
||||||
|
fn-name@~3.0.0:
|
||||||
|
version "3.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/fn-name/-/fn-name-3.0.0.tgz#0596707f635929634d791f452309ab41558e3c5c"
|
||||||
|
integrity sha512-eNMNr5exLoavuAMhIUVsOKF79SWd/zG104ef6sxBTSw+cZc6BXdQXDvYcGvp0VbxVVSp1XDUNoz7mg1xMtSznA==
|
||||||
|
|
||||||
follow-redirects@0.0.3:
|
follow-redirects@0.0.3:
|
||||||
version "0.0.3"
|
version "0.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-0.0.3.tgz#6ce67a24db1fe13f226c1171a72a7ef2b17b8f65"
|
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-0.0.3.tgz#6ce67a24db1fe13f226c1171a72a7ef2b17b8f65"
|
||||||
@ -4926,13 +4937,6 @@ is-hexadecimal@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"
|
resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"
|
||||||
integrity sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==
|
integrity sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==
|
||||||
|
|
||||||
is-nan@^1.3.0:
|
|
||||||
version "1.3.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/is-nan/-/is-nan-1.3.0.tgz#85d1f5482f7051c2019f5673ccebdb06f3b0db03"
|
|
||||||
integrity sha512-z7bbREymOqt2CCaZVly8aC4ML3Xhfi0ekuOnjO2L8vKdl+CttdVoGZQhd4adMFAsxQ5VeRVwORs4tU8RH+HFtQ==
|
|
||||||
dependencies:
|
|
||||||
define-properties "^1.1.3"
|
|
||||||
|
|
||||||
is-number@^3.0.0:
|
is-number@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195"
|
resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195"
|
||||||
@ -6278,7 +6282,7 @@ module-not-found-error@^1.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0"
|
resolved "https://registry.yarnpkg.com/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0"
|
||||||
integrity sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=
|
integrity sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=
|
||||||
|
|
||||||
moment-timezone@0.5.23, moment-timezone@0.5.28, moment-timezone@0.5.31, moment-timezone@^0.5.31:
|
moment-timezone@0.5.23, moment-timezone@0.5.28, moment-timezone@0.5.31:
|
||||||
version "0.5.23"
|
version "0.5.23"
|
||||||
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.23.tgz#7cbb00db2c14c71b19303cb47b0fb0a6d8651463"
|
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.23.tgz#7cbb00db2c14c71b19303cb47b0fb0a6d8651463"
|
||||||
integrity sha512-WHFH85DkCfiNMDX5D3X7hpNH3/PUhjTGcD0U1SgfBGZxJ3qUmJh5FdvaFjcClxOvB3rzdfj4oRffbI38jEnC1w==
|
integrity sha512-WHFH85DkCfiNMDX5D3X7hpNH3/PUhjTGcD0U1SgfBGZxJ3qUmJh5FdvaFjcClxOvB3rzdfj4oRffbI38jEnC1w==
|
||||||
@ -7546,6 +7550,11 @@ propagate@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45"
|
resolved "https://registry.yarnpkg.com/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45"
|
||||||
integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==
|
integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==
|
||||||
|
|
||||||
|
property-expr@^2.0.2:
|
||||||
|
version "2.0.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/property-expr/-/property-expr-2.0.4.tgz#37b925478e58965031bb612ec5b3260f8241e910"
|
||||||
|
integrity sha512-sFPkHQjVKheDNnPvotjQmm3KD3uk1fWKUN7CrpdbwmUx3CrG3QiM8QpTSimvig5vTXmTvjz7+TDvXOI9+4rkcg==
|
||||||
|
|
||||||
proto-list@~1.2.1:
|
proto-list@~1.2.1:
|
||||||
version "1.2.4"
|
version "1.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
|
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
|
||||||
@ -7782,6 +7791,11 @@ rechoir@^0.6.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
resolve "^1.1.6"
|
resolve "^1.1.6"
|
||||||
|
|
||||||
|
regenerator-runtime@^0.13.4:
|
||||||
|
version "0.13.7"
|
||||||
|
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
|
||||||
|
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==
|
||||||
|
|
||||||
regex-not@^1.0.0, regex-not@^1.0.2:
|
regex-not@^1.0.0, regex-not@^1.0.2:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
|
resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
|
||||||
@ -8838,6 +8852,11 @@ symbol-tree@^3.2.4:
|
|||||||
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
|
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
|
||||||
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==
|
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==
|
||||||
|
|
||||||
|
synchronous-promise@^2.0.13:
|
||||||
|
version "2.0.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.15.tgz#07ca1822b9de0001f5ff73595f3d08c4f720eb8e"
|
||||||
|
integrity sha512-k8uzYIkIVwmT+TcglpdN50pS2y1BDcUnBPK9iJeGu0Pl1lOI8pD6wtzgw91Pjpe+RxtTncw32tLxs/R0yNL2Mg==
|
||||||
|
|
||||||
sywac@1.3.0:
|
sywac@1.3.0:
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/sywac/-/sywac-1.3.0.tgz#324789bdb8bd7d0d66625c9144fce81ab5ba6f99"
|
resolved "https://registry.yarnpkg.com/sywac/-/sywac-1.3.0.tgz#324789bdb8bd7d0d66625c9144fce81ab5ba6f99"
|
||||||
@ -9043,6 +9062,11 @@ toidentifier@1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
|
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
|
||||||
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
|
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
|
||||||
|
|
||||||
|
toposort@^2.0.2:
|
||||||
|
version "2.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/toposort/-/toposort-2.0.2.tgz#ae21768175d1559d48bef35420b2f4962f09c330"
|
||||||
|
integrity sha1-riF2gXXRVZ1IvvNUILL0li8JwzA=
|
||||||
|
|
||||||
tough-cookie@4.0.0:
|
tough-cookie@4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.0.0.tgz#d822234eeca882f991f0f908824ad2622ddbece4"
|
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.0.0.tgz#d822234eeca882f991f0f908824ad2622ddbece4"
|
||||||
@ -9806,6 +9830,19 @@ yauzl@^2.10.0:
|
|||||||
buffer-crc32 "~0.2.3"
|
buffer-crc32 "~0.2.3"
|
||||||
fd-slicer "~1.1.0"
|
fd-slicer "~1.1.0"
|
||||||
|
|
||||||
|
yup@0.29.3:
|
||||||
|
version "0.29.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/yup/-/yup-0.29.3.tgz#69a30fd3f1c19f5d9e31b1cf1c2b851ce8045fea"
|
||||||
|
integrity sha512-RNUGiZ/sQ37CkhzKFoedkeMfJM0vNQyaz+wRZJzxdKE7VfDeVKH8bb4rr7XhRLbHJz5hSjoDNwMEIaKhuMZ8gQ==
|
||||||
|
dependencies:
|
||||||
|
"@babel/runtime" "^7.10.5"
|
||||||
|
fn-name "~3.0.0"
|
||||||
|
lodash "^4.17.15"
|
||||||
|
lodash-es "^4.17.11"
|
||||||
|
property-expr "^2.0.2"
|
||||||
|
synchronous-promise "^2.0.13"
|
||||||
|
toposort "^2.0.2"
|
||||||
|
|
||||||
zip-stream@^1.1.0:
|
zip-stream@^1.1.0:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-1.2.0.tgz#a8bc45f4c1b49699c6b90198baacaacdbcd4ba04"
|
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-1.2.0.tgz#a8bc45f4c1b49699c6b90198baacaacdbcd4ba04"
|
||||||
|
Loading…
Reference in New Issue
Block a user