]>
Commit | Line | Data |
---|---|---|
da854ddd C |
1 | import { logger } from '../../../helpers/logger' |
2 | import { doRequest } from '../../../helpers/requests' | |
60650c77 | 3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
e12a0092 | 4 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
afffe988 C |
5 | |
6 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | |
7 | logger.info('Processing ActivityPub broadcast in job %d.', jobId) | |
8 | ||
63c93323 | 9 | const body = await computeBody(payload) |
e12a0092 | 10 | const httpSignatureOptions = await buildSignedRequestOptions(payload) |
afffe988 C |
11 | |
12 | const options = { | |
13 | method: 'POST', | |
14 | uri: '', | |
e12a0092 C |
15 | json: body, |
16 | httpSignature: httpSignatureOptions | |
afffe988 C |
17 | } |
18 | ||
60650c77 C |
19 | const badUrls: string[] = [] |
20 | const goodUrls: string[] = [] | |
21 | ||
afffe988 C |
22 | for (const uri of payload.uris) { |
23 | options.uri = uri | |
0032ebe9 C |
24 | |
25 | try { | |
26 | await doRequest(options) | |
60650c77 | 27 | goodUrls.push(uri) |
0032ebe9 | 28 | } catch (err) { |
60650c77 C |
29 | const isRetryingLater = await maybeRetryRequestLater(err, payload, uri) |
30 | if (isRetryingLater === false) badUrls.push(uri) | |
0032ebe9 | 31 | } |
afffe988 | 32 | } |
60650c77 C |
33 | |
34 | return ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes(goodUrls, badUrls, undefined) | |
afffe988 C |
35 | } |
36 | ||
37 | function onError (err: Error, jobId: number) { | |
38 | logger.error('Error when broadcasting ActivityPub request in job %d.', jobId, err) | |
39 | return Promise.resolve() | |
40 | } | |
41 | ||
42 | function onSuccess (jobId: number) { | |
43 | logger.info('Job %d is a success.', jobId) | |
44 | return Promise.resolve() | |
45 | } | |
46 | ||
47 | // --------------------------------------------------------------------------- | |
48 | ||
49 | export { | |
50 | process, | |
51 | onError, | |
52 | onSuccess | |
53 | } |