diff options
Diffstat (limited to 'server/lib/job-queue/handlers/activitypub-http-broadcast.ts')
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-http-broadcast.ts | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts deleted file mode 100644 index 8904d086f..000000000 --- a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | import { Job } from 'bullmq' | ||
2 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from '@server/lib/activitypub/send' | ||
3 | import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache' | ||
4 | import { parallelHTTPBroadcastFromWorker, sequentialHTTPBroadcastFromWorker } from '@server/lib/worker/parent-process' | ||
5 | import { ActivitypubHttpBroadcastPayload } from '@shared/models' | ||
6 | import { logger } from '../../../helpers/logger' | ||
7 | |||
8 | // Prefer using a worker thread for HTTP requests because on high load we may have to sign many requests, which can be CPU intensive | ||
9 | |||
10 | async function processActivityPubHttpSequentialBroadcast (job: Job<ActivitypubHttpBroadcastPayload>) { | ||
11 | logger.info('Processing ActivityPub broadcast in job %s.', job.id) | ||
12 | |||
13 | const requestOptions = await buildRequestOptions(job.data) | ||
14 | |||
15 | const { badUrls, goodUrls } = await sequentialHTTPBroadcastFromWorker({ uris: job.data.uris, requestOptions }) | ||
16 | |||
17 | return ActorFollowHealthCache.Instance.updateActorFollowsHealth(goodUrls, badUrls) | ||
18 | } | ||
19 | |||
20 | async function processActivityPubParallelHttpBroadcast (job: Job<ActivitypubHttpBroadcastPayload>) { | ||
21 | logger.info('Processing ActivityPub parallel broadcast in job %s.', job.id) | ||
22 | |||
23 | const requestOptions = await buildRequestOptions(job.data) | ||
24 | |||
25 | const { badUrls, goodUrls } = await parallelHTTPBroadcastFromWorker({ uris: job.data.uris, requestOptions }) | ||
26 | |||
27 | return ActorFollowHealthCache.Instance.updateActorFollowsHealth(goodUrls, badUrls) | ||
28 | } | ||
29 | |||
30 | // --------------------------------------------------------------------------- | ||
31 | |||
32 | export { | ||
33 | processActivityPubHttpSequentialBroadcast, | ||
34 | processActivityPubParallelHttpBroadcast | ||
35 | } | ||
36 | |||
37 | // --------------------------------------------------------------------------- | ||
38 | |||
39 | async function buildRequestOptions (payload: ActivitypubHttpBroadcastPayload) { | ||
40 | const body = await computeBody(payload) | ||
41 | const httpSignatureOptions = await buildSignedRequestOptions({ signatureActorId: payload.signatureActorId, hasPayload: true }) | ||
42 | |||
43 | return { | ||
44 | method: 'POST' as 'POST', | ||
45 | json: body, | ||
46 | httpSignature: httpSignatureOptions, | ||
47 | headers: buildGlobalHeaders(body) | ||
48 | } | ||
49 | } | ||