mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Made name parameter required for one off jobs
refs https://github.com/TryGhost/Toolbox/issues/359 - Without a "name" parameter it's impossible to identify a job in the storage. It was missed during the PoC inmplementation
This commit is contained in:
parent
8c3473e5e0
commit
013051a6c9
2 changed files with 20 additions and 1 deletions
|
@ -179,12 +179,18 @@ class JobManager {
|
|||
*
|
||||
* @param {Object} GhostJob - job options
|
||||
* @prop {Function | String} GhostJob.job - function or path to a module defining a job
|
||||
* @prop {String} [GhostJob.name] - unique job name, if not provided takes function name or job script filename
|
||||
* @prop {String} GhostJob.name - unique job name, if not provided takes function name or job script filename
|
||||
* @prop {String | Date} [GhostJob.at] - Date, cron or human readable schedule format. Manage will do immediate execution if not specified. Not supported for "inline" jobs
|
||||
* @prop {Object} [GhostJob.data] - data to be passed into the job
|
||||
* @prop {Boolean} [GhostJob.offloaded] - creates an "offloaded" job running in a worker thread by default. If set to "false" runs an "inline" job on the same event loop
|
||||
*/
|
||||
async addOneOffJob({name, job, data, offloaded = true}) {
|
||||
if (!name) {
|
||||
throw new IncorrectUsageError({
|
||||
message: `The name parameter is required for a one off job.`
|
||||
});
|
||||
}
|
||||
|
||||
const persistedJob = await this._jobsRepository.read(name);
|
||||
|
||||
if (persistedJob) {
|
||||
|
|
|
@ -253,6 +253,19 @@ describe('Job Manager', function () {
|
|||
});
|
||||
|
||||
describe('Add one off job', function () {
|
||||
it('throws if name parameter is not provided', async function () {
|
||||
const jobManager = new JobManager({});
|
||||
|
||||
try {
|
||||
await jobManager.addOneOffJob({
|
||||
job: () => {}
|
||||
});
|
||||
throw new Error('should have thrown');
|
||||
} catch (err) {
|
||||
should.equal(err.message, 'The name parameter is required for a one off job.');
|
||||
}
|
||||
});
|
||||
|
||||
it('adds job to the queue when it is a unique one', async function () {
|
||||
const spy = sinon.spy();
|
||||
const JobModel = {
|
||||
|
|
Loading…
Add table
Reference in a new issue