diff options
Diffstat (limited to 'server/lib/jobs/job-scheduler.ts')
-rw-r--r-- | server/lib/jobs/job-scheduler.ts | 13 |
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' | |||
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
5 | import { database as db, JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers' | 5 | import { database as db, JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers' |
6 | import { JobInstance } from '../../models' | 6 | import { JobInstance } from '../../models' |
7 | import { error } from 'util' | ||
7 | 8 | ||
8 | export interface JobHandler<P, T> { | 9 | export 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 | } |