]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts
Add beautiful loading bar
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / activitypub-http-job-scheduler / activitypub-http-broadcast-handler.ts
CommitLineData
afffe988 1import { logger } from '../../../helpers'
afffe988 2import { doRequest } from '../../../helpers/requests'
63c93323 3import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
afffe988
C
4
5async function process (payload: ActivityPubHttpPayload, jobId: number) {
6 logger.info('Processing ActivityPub broadcast in job %d.', jobId)
7
63c93323 8 const body = await computeBody(payload)
afffe988
C
9
10 const options = {
11 method: 'POST',
12 uri: '',
63c93323 13 json: body
afffe988
C
14 }
15
16 for (const uri of payload.uris) {
17 options.uri = uri
0032ebe9
C
18
19 try {
20 await doRequest(options)
21 } catch (err) {
22 await maybeRetryRequestLater(err, payload, uri)
23 }
afffe988
C
24 }
25}
26
27function onError (err: Error, jobId: number) {
28 logger.error('Error when broadcasting ActivityPub request in job %d.', jobId, err)
29 return Promise.resolve()
30}
31
32function onSuccess (jobId: number) {
33 logger.info('Job %d is a success.', jobId)
34 return Promise.resolve()
35}
36
37// ---------------------------------------------------------------------------
38
39export {
40 process,
41 onError,
42 onSuccess
43}