]>
Commit | Line | Data |
---|---|---|
1 | import { map } from 'bluebird' | |
2 | import { Job } from 'bull' | |
3 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from '@server/lib/activitypub/send' | |
4 | import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache' | |
5 | import { ActivitypubHttpBroadcastPayload } from '@shared/models' | |
6 | import { logger } from '../../../helpers/logger' | |
7 | import { doRequest } from '../../../helpers/requests' | |
8 | import { BROADCAST_CONCURRENCY } from '../../../initializers/constants' | |
9 | ||
10 | async function processActivityPubHttpBroadcast (job: Job) { | |
11 | logger.info('Processing ActivityPub broadcast in job %d.', job.id) | |
12 | ||
13 | const payload = job.data as ActivitypubHttpBroadcastPayload | |
14 | ||
15 | const body = await computeBody(payload) | |
16 | const httpSignatureOptions = await buildSignedRequestOptions(payload) | |
17 | ||
18 | const options = { | |
19 | method: 'POST' as 'POST', | |
20 | json: body, | |
21 | httpSignature: httpSignatureOptions, | |
22 | headers: buildGlobalHeaders(body) | |
23 | } | |
24 | ||
25 | const badUrls: string[] = [] | |
26 | const goodUrls: string[] = [] | |
27 | ||
28 | await map(payload.uris, async uri => { | |
29 | try { | |
30 | await doRequest(uri, options) | |
31 | goodUrls.push(uri) | |
32 | } catch (err) { | |
33 | logger.debug('HTTP broadcast to %s failed.', uri, { err }) | |
34 | badUrls.push(uri) | |
35 | } | |
36 | }, { concurrency: BROADCAST_CONCURRENCY }) | |
37 | ||
38 | return ActorFollowHealthCache.Instance.updateActorFollowsHealth(goodUrls, badUrls) | |
39 | } | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | export { | |
44 | processActivityPubHttpBroadcast | |
45 | } |