]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - 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
1import { doRequest, logger } from '../../../helpers'
2import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
3
4async 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
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}