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