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