mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
Added support for job execution from module path
no issue - Jobs should not always be functions, one of the standard practices is having a job defined in a module as a self contained executable function - First parameter of `addJob` function now also handles path to modules which it imports and executes
This commit is contained in:
parent
70b42e3a75
commit
c85ec6aaa5
@ -30,14 +30,18 @@ class JobManager {
|
|||||||
/**
|
/**
|
||||||
* Adds job to queue
|
* Adds job to queue
|
||||||
*
|
*
|
||||||
* @param {Function} job - function to be executed in the queue
|
* @param {Function|String} job - function or path to a module defining a job
|
||||||
* @param {Object} [data] - data to be passed into the job
|
* @param {Object} [data] - data to be passed into the job
|
||||||
*/
|
*/
|
||||||
addJob(job, data) {
|
addJob(job, data) {
|
||||||
this.logging.info('Adding one off job to the queue');
|
this.logging.info('Adding one off job to the queue');
|
||||||
|
|
||||||
this.queue.push(async () => {
|
this.queue.push(async () => {
|
||||||
|
if (typeof job === 'function') {
|
||||||
await job(data);
|
await job(data);
|
||||||
|
} else {
|
||||||
|
await require(job)(data);
|
||||||
|
}
|
||||||
}, handler);
|
}, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +49,8 @@ class JobManager {
|
|||||||
* Schedules recuring job
|
* Schedules recuring job
|
||||||
*
|
*
|
||||||
* @param {String} when - cron or human readable schedule format
|
* @param {String} when - cron or human readable schedule format
|
||||||
* @param {Function|String} job - function or path to a file defining a job
|
* @param {Function|String} job - function or path to a module defining a job
|
||||||
* @param {Object} data - data to be passed into the job
|
* @param {Object} [data] - data to be passed into the job
|
||||||
*/
|
*/
|
||||||
scheduleJob(when, job, data) {
|
scheduleJob(when, job, data) {
|
||||||
let schedule;
|
let schedule;
|
||||||
|
Loading…
Reference in New Issue
Block a user