Added defensive code for non-persistent job manager

refs https://github.com/TryGhost/Toolbox/issues/359

- It's up to a user to decide initializing the job manager without a "jobModel". In these cases the regular recurring job scheduling should work as it did before
This commit is contained in:
Naz 2022-07-26 18:00:40 +01:00
parent 9973b5419c
commit 822549c9ef

View File

@ -66,10 +66,13 @@ class JobManager {
this._jobMessageHandler({name, message: 'started'});
});
if (JobModel) {
this._jobsRepository = new JobsRepository({JobModel});
}
}
async _jobMessageHandler({name, message}) {
if (this._jobsRepository) {
if (message === 'started') {
const job = await this._jobsRepository.read(name);
@ -90,9 +93,11 @@ class JobManager {
}
}
}
}
async _jobErrorHandler(error, workerMeta) {
const job = await this._jobsRepository.read(workerMeta.name);
async _jobErrorHandler(error, jobMeta) {
if (this._jobsRepository) {
const job = await this._jobsRepository.read(jobMeta.name);
if (job) {
await this._jobsRepository.update(job.id, {
@ -100,6 +105,7 @@ class JobManager {
});
}
}
}
/**
* By default schedules an "offloaded" job. If `offloaded: true` parameter is set,