]>
Commit | Line | Data |
---|---|---|
3fd3ab2d | 1 | import { doRequest, logger } from '../../../helpers' |
63c93323 | 2 | import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
afffe988 C |
3 | |
4 | async 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 | ||
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 | } |