diff --git a/ghost/core/core/server/models/job.js b/ghost/core/core/server/models/job.js new file mode 100644 index 0000000000..754396d3ed --- /dev/null +++ b/ghost/core/core/server/models/job.js @@ -0,0 +1,9 @@ +const ghostBookshelf = require('./base'); + +const Job = ghostBookshelf.Model.extend({ + tableName: 'jobs' +}); + +module.exports = { + Job: ghostBookshelf.model('Job', Job) +}; diff --git a/ghost/core/core/server/services/jobs/job-service.js b/ghost/core/core/server/services/jobs/job-service.js index d926e5c02d..4676e6f0f0 100644 --- a/ghost/core/core/server/services/jobs/job-service.js +++ b/ghost/core/core/server/services/jobs/job-service.js @@ -5,6 +5,7 @@ const JobManager = require('@tryghost/job-manager'); const logging = require('@tryghost/logging'); +const models = require('../../models'); const sentry = require('../../../shared/sentry'); const errorHandler = (error, workerMeta) => { @@ -38,7 +39,7 @@ const initTestMode = () => { }, 5000); }; -const jobManager = new JobManager({errorHandler, workerMessageHandler}); +const jobManager = new JobManager({errorHandler, workerMessageHandler, JobModel: models.Job}); module.exports = jobManager; module.exports.initTestMode = initTestMode; diff --git a/ghost/core/core/server/web/api/testmode/jobs/graceful-job.js b/ghost/core/core/server/web/api/testmode/jobs/graceful-job.js index f56a5ee4a2..02d1b74c62 100644 --- a/ghost/core/core/server/web/api/testmode/jobs/graceful-job.js +++ b/ghost/core/core/server/web/api/testmode/jobs/graceful-job.js @@ -37,7 +37,7 @@ const internalContext = {context: {internal: true}}; if (shutdown) { postParentPortMessage(`Job shutting down gracefully`); - process.exit(0); + parentPort.postMessage('done'); } postParentPortMessage(`Fetching posts`); @@ -46,5 +46,5 @@ const internalContext = {context: {internal: true}}; postParentPortMessage(`Found ${posts.data.length} posts. First one: ${posts.data[0].toJSON().slug}`); postParentPortMessage('Graceful job has completed!'); - process.exit(0); + parentPort.postMessage('done'); })(); diff --git a/ghost/core/core/server/web/api/testmode/routes.js b/ghost/core/core/server/web/api/testmode/routes.js index f9f0a7ddf1..dd342c47c2 100644 --- a/ghost/core/core/server/web/api/testmode/routes.js +++ b/ghost/core/core/server/web/api/testmode/routes.js @@ -44,6 +44,20 @@ module.exports = function testRoutes() { res.sendStatus(202); }); + router.get('/oneoff/:name', (req, res) => { + logging.info('Create Slow Job with timeout of', req.params.name); + + const options = {}; + + options.solo = true; + options.name = req.params.name; + options.job = path.resolve(__dirname, 'jobs', `${options.name}.js`); + + jobsService.addOneOffJob(options); + + res.sendStatus(202); + }); + router.get('/schedule/:schedule/:name*?', (req, res) => { if (!req.params.schedule) { return res.sendStatus(400, 'schedule parameter cannot be mepty'); diff --git a/ghost/core/package.json b/ghost/core/package.json index 6e018159a3..baff191bb7 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -77,7 +77,7 @@ "@tryghost/express-dynamic-redirects": "0.0.0", "@tryghost/helpers": "1.1.71", "@tryghost/image-transform": "1.1.0", - "@tryghost/job-manager": "0.8.25", + "@tryghost/job-manager": "0.9.0", "@tryghost/kg-card-factory": "3.1.3", "@tryghost/kg-default-atoms": "3.1.2", "@tryghost/kg-default-cards": "5.16.2", diff --git a/yarn.lock b/yarn.lock index 41284d5ed9..6b6bf93a1c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1748,10 +1748,10 @@ "@tryghost/errors" "^1.2.14" jest-snapshot "^28.0.0" -"@tryghost/job-manager@0.8.25": - version "0.8.25" - resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.8.25.tgz#9c208e4fa4ca4719c64a432b67039396cfdc0796" - integrity sha512-gkhhfWZFcpsfS4NqECqJvDIi8yIR+V7dngSsT9N011BOriwu5jr/weoGkGhIkZdIK79GNzVIHR9PBaAAEjZXNw== +"@tryghost/job-manager@0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.9.0.tgz#ca6733f75cb927de3a52d633bc4ae3e73a026164" + integrity sha512-UGB1qqwLvqjPLGKAiC/qgCAhSGIZHUD6nxcdHtjIB9G1yGFGi6Ki2bu7QQRsmuttUWHxZzYeKLmhuCBuuEOZmw== dependencies: "@breejs/later" "^4.0.2" "@tryghost/logging" "^2.0.0"