aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs/job-scheduler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/jobs/job-scheduler.ts')
-rw-r--r--server/lib/jobs/job-scheduler.ts13
1 files changed, 9 insertions, 4 deletions
diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts
index f10f745b3..b25bb7ab3 100644
--- a/server/lib/jobs/job-scheduler.ts
+++ b/server/lib/jobs/job-scheduler.ts
@@ -4,6 +4,7 @@ import { JobCategory } from '../../../shared'
4import { logger } from '../../helpers' 4import { logger } from '../../helpers'
5import { database as db, JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers' 5import { database as db, JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers'
6import { JobInstance } from '../../models' 6import { JobInstance } from '../../models'
7import { error } from 'util'
7 8
8export interface JobHandler<P, T> { 9export interface JobHandler<P, T> {
9 process (data: object, jobId: number): Promise<T> 10 process (data: object, jobId: number): Promise<T>
@@ -80,8 +81,12 @@ class JobScheduler<P, T> {
80 private async processJob (job: JobInstance, callback: (err: Error) => void) { 81 private async processJob (job: JobInstance, callback: (err: Error) => void) {
81 const jobHandler = this.jobHandlers[job.handlerName] 82 const jobHandler = this.jobHandlers[job.handlerName]
82 if (jobHandler === undefined) { 83 if (jobHandler === undefined) {
83 logger.error('Unknown job handler for job %s.', job.handlerName) 84 const errorString = 'Unknown job handler ' + job.handlerName + ' for job ' + job.id
84 return callback(null) 85 logger.error(errorString)
86
87 const error = new Error(errorString)
88 await this.onJobError(jobHandler, job, error)
89 return callback(error)
85 } 90 }
86 91
87 logger.info('Processing job %d with handler %s.', job.id, job.handlerName) 92 logger.info('Processing job %d with handler %s.', job.id, job.handlerName)
@@ -103,7 +108,7 @@ class JobScheduler<P, T> {
103 } 108 }
104 } 109 }
105 110
106 callback(null) 111 return callback(null)
107 } 112 }
108 113
109 private async onJobError (jobHandler: JobHandler<P, T>, job: JobInstance, err: Error) { 114 private async onJobError (jobHandler: JobHandler<P, T>, job: JobInstance, err: Error) {
@@ -111,7 +116,7 @@ class JobScheduler<P, T> {
111 116
112 try { 117 try {
113 await job.save() 118 await job.save()
114 await jobHandler.onError(err, job.id) 119 if (jobHandler) await jobHandler.onError(err, job.id)
115 } catch (err) { 120 } catch (err) {
116 this.cannotSaveJobError(err) 121 this.cannotSaveJobError(err)
117 } 122 }