]>
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 broadcast in job %d.', jobId) | |
6 | ||
63c93323 | 7 | const body = await computeBody(payload) |
afffe988 C |
8 | |
9 | const options = { | |
10 | method: 'POST', | |
11 | uri: '', | |
63c93323 | 12 | json: body |
afffe988 C |
13 | } |
14 | ||
15 | for (const uri of payload.uris) { | |
16 | options.uri = uri | |
0032ebe9 C |
17 | |
18 | try { | |
19 | await doRequest(options) | |
20 | } catch (err) { | |
21 | await maybeRetryRequestLater(err, payload, uri) | |
22 | } | |
afffe988 C |
23 | } |
24 | } | |
25 | ||
26 | function onError (err: Error, jobId: number) { | |
27 | logger.error('Error when broadcasting ActivityPub request in job %d.', jobId, err) | |
28 | return Promise.resolve() | |
29 | } | |
30 | ||
31 | function onSuccess (jobId: number) { | |
32 | logger.info('Job %d is a success.', jobId) | |
33 | return Promise.resolve() | |
34 | } | |
35 | ||
36 | // --------------------------------------------------------------------------- | |
37 | ||
38 | export { | |
39 | process, | |
40 | onError, | |
41 | onSuccess | |
42 | } |