diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-23 14:19:55 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 0032ebe94aa83fab761c7de3ceb6210ac4532824 (patch) | |
tree | 3ea407d7ea6de4c7f7bc66caba7e23c0cc4036e3 /server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts | |
parent | d52eb8f656242c7e34afdb2dee681861fb9bce35 (diff) | |
download | PeerTube-0032ebe94aa83fab761c7de3ceb6210ac4532824.tar.gz PeerTube-0032ebe94aa83fab761c7de3ceb6210ac4532824.tar.zst PeerTube-0032ebe94aa83fab761c7de3ceb6210ac4532824.zip |
Federate likes/dislikes
Diffstat (limited to 'server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts')
-rw-r--r-- | server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts index aef217ce7..ccf109935 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts | |||
@@ -4,12 +4,16 @@ import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-h | |||
4 | import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler' | 4 | import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler' |
5 | import * as activitypubHttpFetcherHandler from './activitypub-http-fetcher-handler' | 5 | import * as activitypubHttpFetcherHandler from './activitypub-http-fetcher-handler' |
6 | import { JobCategory } from '../../../../shared' | 6 | import { JobCategory } from '../../../../shared' |
7 | import { ACTIVITY_PUB } from '../../../initializers/constants' | ||
8 | import { logger } from '../../../helpers/logger' | ||
7 | 9 | ||
8 | type ActivityPubHttpPayload = { | 10 | type ActivityPubHttpPayload = { |
9 | uris: string[] | 11 | uris: string[] |
10 | signatureAccountId?: number | 12 | signatureAccountId?: number |
11 | body?: any | 13 | body?: any |
14 | attemptNumber?: number | ||
12 | } | 15 | } |
16 | |||
13 | const jobHandlers: { [ handlerName: string ]: JobHandler<ActivityPubHttpPayload, void> } = { | 17 | const jobHandlers: { [ handlerName: string ]: JobHandler<ActivityPubHttpPayload, void> } = { |
14 | activitypubHttpBroadcastHandler, | 18 | activitypubHttpBroadcastHandler, |
15 | activitypubHttpUnicastHandler, | 19 | activitypubHttpUnicastHandler, |
@@ -19,7 +23,25 @@ const jobCategory: JobCategory = 'activitypub-http' | |||
19 | 23 | ||
20 | const activitypubHttpJobScheduler = new JobScheduler(jobCategory, jobHandlers) | 24 | const activitypubHttpJobScheduler = new JobScheduler(jobCategory, jobHandlers) |
21 | 25 | ||
26 | function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPayload, uri: string) { | ||
27 | logger.warn('Cannot make request to %s.', uri, err) | ||
28 | |||
29 | let attemptNumber = payload.attemptNumber || 1 | ||
30 | attemptNumber += 1 | ||
31 | |||
32 | if (attemptNumber < ACTIVITY_PUB.MAX_HTTP_ATTEMPT) { | ||
33 | logger.debug('Retrying request to %s (attempt %d/%d).', uri, attemptNumber, ACTIVITY_PUB.MAX_HTTP_ATTEMPT, err) | ||
34 | |||
35 | const newPayload = Object.assign(payload, { | ||
36 | uris: [ uri ], | ||
37 | attemptNumber | ||
38 | }) | ||
39 | return activitypubHttpJobScheduler.createJob(undefined, 'activitypubHttpUnicastHandler', newPayload) | ||
40 | } | ||
41 | } | ||
42 | |||
22 | export { | 43 | export { |
23 | ActivityPubHttpPayload, | 44 | ActivityPubHttpPayload, |
24 | activitypubHttpJobScheduler | 45 | activitypubHttpJobScheduler, |
46 | maybeRetryRequestLater | ||
25 | } | 47 | } |