Fixed an unhandled exception in job manager

closes https://github.com/TryGhost/Toolbox/issues/402

- The SQL error was thrown whenever a job error was happening and was trying to persist an error. Persisting an error should only happen for "named" one-off jobs, instead of just one-off jobs.
This commit is contained in:
Naz 2022-10-07 18:41:11 +08:00
parent b3a33760ac
commit 54c19226bf
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View File

@ -114,7 +114,7 @@ class JobManager {
}
async _jobErrorHandler(error, jobMeta) {
if (this._jobsRepository) {
if (this._jobsRepository && jobMeta.name) {
const job = await this._jobsRepository.read(jobMeta.name);
if (job) {

View File

@ -65,7 +65,12 @@ describe('Job Manager', function () {
it('handles failed job gracefully', async function () {
const spy = sinon.stub().throws();
const jobManager = new JobManager({});
const jobModelSpy = {
findOne: sinon.spy()
};
const jobManager = new JobManager({
JobModel: jobModelSpy
});
jobManager.addJob({
job: spy,
@ -81,6 +86,8 @@ describe('Job Manager', function () {
should(spy.called).be.true();
should(spy.args[0][0]).equal('test data');
should(logging.error.called).be.true();
// a one-off job without a name should not have persistance
should(jobModelSpy.findOne.called).be.false();
});
});