mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
no issue - We need an ability to early test scheduled jobs to refine the new feature and it's API. Should be used with caution - To schedule an example scheduled job every 30 seconds run following request: `curl http://localhost:2368/ghost/api/schedule/every%2030%20seconds`
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
const logging = require('../../../shared/logging');
|
|
const express = require('../../../shared/express');
|
|
const jobService = require('../../services/jobs');
|
|
|
|
/** A bunch of helper routes for testing purposes */
|
|
module.exports = function testRoutes() {
|
|
const router = express.Router('canary admin');
|
|
|
|
router.get('/500', (req, res) => res.sendStatus(500));
|
|
router.get('/400', (req, res) => res.sendStatus(400));
|
|
router.get('/404', (req, res) => res.sendStatus(404));
|
|
router.get('/slow/:timeout', (req, res) => {
|
|
if (!req.params || !req.params.timeout) {
|
|
return res.sendStatus(200);
|
|
}
|
|
const timeout = req.params.timeout * 1000;
|
|
logging.info('Begin Slow Request with timeout of', timeout);
|
|
setTimeout(() => {
|
|
logging.info('End Slow Request', timeout);
|
|
res.sendStatus(200);
|
|
}, timeout);
|
|
});
|
|
router.get('/job/:timeout', (req, res) => {
|
|
if (!req.params || !req.params.timeout) {
|
|
return res.sendStatus(200);
|
|
}
|
|
|
|
const timeout = req.params.timeout * 1000;
|
|
logging.info('Create Slow Job with timeout of', timeout);
|
|
jobService.addJob(() => {
|
|
return new Promise((resolve) => {
|
|
logging.info('Start Slow Job');
|
|
setTimeout(() => {
|
|
logging.info('End Slow Job', timeout);
|
|
resolve();
|
|
}, timeout);
|
|
});
|
|
});
|
|
|
|
res.sendStatus(202);
|
|
});
|
|
|
|
router.get('/schedule/:schedule', (req, res) => {
|
|
if (!req.params.schedule) {
|
|
return res.sendStatus(400, 'schedule parameter cannot be mepty');
|
|
}
|
|
|
|
const schedule = req.params.schedule;
|
|
logging.info('Achedule a Job with schedule of:', schedule);
|
|
|
|
jobService.scheduleJob(() => {
|
|
return new Promise((resolve) => {
|
|
logging.info('Start scheduled Job');
|
|
|
|
setTimeout(() => {
|
|
logging.info('End scheduled Job run', schedule);
|
|
resolve();
|
|
}, 20 * 1000);
|
|
});
|
|
}, {}, schedule);
|
|
|
|
res.sendStatus(202);
|
|
});
|
|
|
|
return router;
|
|
};
|