aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/jobs')
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts1
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts1
-rw-r--r--server/lib/jobs/job-scheduler.ts13
3 files changed, 11 insertions, 4 deletions
diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts
index 799b86e1c..2f1d9ee92 100644
--- a/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts
+++ b/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts
@@ -6,6 +6,7 @@ async function process (payload: HTTPRequestPayload, jobId: number) {
6 logger.info('Processing broadcast in job %d.', jobId) 6 logger.info('Processing broadcast in job %d.', jobId)
7 7
8 const options = { 8 const options = {
9 method: 'POST',
9 uri: '', 10 uri: '',
10 json: payload.body 11 json: payload.body
11 } 12 }
diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts
index 13451f042..3a1a7fabf 100644
--- a/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts
+++ b/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts
@@ -7,6 +7,7 @@ async function process (payload: HTTPRequestPayload, jobId: number) {
7 7
8 const uri = payload.uris[0] 8 const uri = payload.uris[0]
9 const options = { 9 const options = {
10 method: 'POST',
10 uri, 11 uri,
11 json: payload.body 12 json: payload.body
12 } 13 }
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 }