aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs/http-request-job-scheduler
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/jobs/http-request-job-scheduler')
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts36
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts22
-rw-r--r--server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts34
-rw-r--r--server/lib/jobs/http-request-job-scheduler/index.ts1
4 files changed, 0 insertions, 93 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
deleted file mode 100644
index ccb008e4d..000000000
--- a/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts
+++ /dev/null
@@ -1,36 +0,0 @@
1import { logger } from '../../../helpers'
2import { doRequest } from '../../../helpers/requests'
3import { HTTPRequestPayload } from './http-request-job-scheduler'
4
5async function process (payload: HTTPRequestPayload, jobId: number) {
6 logger.info('Processing broadcast in job %d.', jobId)
7
8 const options = {
9 method: 'POST',
10 uri: '',
11 json: payload.body
12 }
13
14 for (const uri of payload.uris) {
15 options.uri = uri
16 await doRequest(options)
17 }
18}
19
20function onError (err: Error, jobId: number) {
21 logger.error('Error when broadcasting request in job %d.', jobId, err)
22 return Promise.resolve()
23}
24
25function onSuccess (jobId: number) {
26 logger.info('Job %d is a success.', jobId)
27 return Promise.resolve()
28}
29
30// ---------------------------------------------------------------------------
31
32export {
33 process,
34 onError,
35 onSuccess
36}
diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts
deleted file mode 100644
index ad3349866..000000000
--- a/server/lib/jobs/http-request-job-scheduler/http-request-job-scheduler.ts
+++ /dev/null
@@ -1,22 +0,0 @@
1import { JobScheduler, JobHandler } from '../job-scheduler'
2
3import * as httpRequestBroadcastHandler from './http-request-broadcast-handler'
4import * as httpRequestUnicastHandler from './http-request-unicast-handler'
5import { JobCategory } from '../../../../shared'
6
7type HTTPRequestPayload = {
8 uris: string[]
9 body: any
10}
11const jobHandlers: { [ handlerName: string ]: JobHandler<HTTPRequestPayload, void> } = {
12 httpRequestBroadcastHandler,
13 httpRequestUnicastHandler
14}
15const jobCategory: JobCategory = 'http-request'
16
17const httpRequestJobScheduler = new JobScheduler(jobCategory, jobHandlers)
18
19export {
20 HTTPRequestPayload,
21 httpRequestJobScheduler
22}
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
deleted file mode 100644
index 9e4e73891..000000000
--- a/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts
+++ /dev/null
@@ -1,34 +0,0 @@
1import { logger } from '../../../helpers'
2import { doRequest } from '../../../helpers/requests'
3import { HTTPRequestPayload } from './http-request-job-scheduler'
4
5async function process (payload: HTTPRequestPayload, jobId: number) {
6 logger.info('Processing unicast in job %d.', jobId)
7
8 const uri = payload.uris[0]
9 const options = {
10 method: 'POST',
11 uri,
12 json: payload.body
13 }
14
15 await doRequest(options)
16}
17
18function onError (err: Error, jobId: number) {
19 logger.error('Error when sending request in job %d.', jobId, err)
20 return Promise.resolve()
21}
22
23function onSuccess (jobId: number) {
24 logger.info('Job %d is a success.', jobId)
25 return Promise.resolve()
26}
27
28// ---------------------------------------------------------------------------
29
30export {
31 process,
32 onError,
33 onSuccess
34}
diff --git a/server/lib/jobs/http-request-job-scheduler/index.ts b/server/lib/jobs/http-request-job-scheduler/index.ts
deleted file mode 100644
index 4d2573296..000000000
--- a/server/lib/jobs/http-request-job-scheduler/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './http-request-job-scheduler'