mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14: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
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
addJob(job, data) {
|
||||
this.logging.info('Adding one off job to the queue');
|
||||
|
||||
this.queue.push(async () => {
|
||||
await job(data);
|
||||
if (typeof job === 'function') {
|
||||
await job(data);
|
||||
} else {
|
||||
await require(job)(data);
|
||||
}
|
||||
}, handler);
|
||||
}
|
||||
|
||||
@ -45,8 +49,8 @@ class JobManager {
|
||||
* Schedules recuring job
|
||||
*
|
||||
* @param {String} when - cron or human readable schedule format
|
||||
* @param {Function|String} job - function or path to a file defining a job
|
||||
* @param {Object} data - data to be passed into the job
|
||||
* @param {Function|String} job - function or path to a module defining a job
|
||||
* @param {Object} [data] - data to be passed into the job
|
||||
*/
|
||||
scheduleJob(when, job, data) {
|
||||
let schedule;
|
||||
|
Loading…
Reference in New Issue
Block a user