]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
Begin moving video channel to actor
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / activitypub-http-job-scheduler / activitypub-http-unicast-handler.ts
1 import { doRequest, logger } from '../../../helpers'
2 import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
3
4 async function process (payload: ActivityPubHttpPayload, jobId: number) {
5 logger.info('Processing ActivityPub unicast in job %d.', jobId)
6
7 const body = await computeBody(payload)
8
9 const uri = payload.uris[0]
10 const options = {
11 method: 'POST',
12 uri,
13 json: body
14 }
15
16 try {
17 await doRequest(options)
18 } catch (err) {
19 await maybeRetryRequestLater(err, payload, uri)
20 throw err
21 }
22 }
23
24 function onError (err: Error, jobId: number) {
25 logger.error('Error when sending ActivityPub request in job %d.', jobId, err)
26 return Promise.resolve()
27 }
28
29 function onSuccess (jobId: number) {
30 logger.info('Job %d is a success.', jobId)
31 return Promise.resolve()
32 }
33
34 // ---------------------------------------------------------------------------
35
36 export {
37 process,
38 onError,
39 onSuccess
40 }