aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/jobs
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-11 09:35:50 +0100
committerChocobozzz <me@florianbigard.com>2018-01-11 09:35:50 +0100
commit60650c77c8a2a98e92d869b237ae4900f369a8fc (patch)
tree7304a7591b5b23b99d219c4d06c6bd5c4c58c1c2 /server/lib/jobs
parent7ae71355c40e9065f83d3fc77b6750d1929ac201 (diff)
downloadPeerTube-60650c77c8a2a98e92d869b237ae4900f369a8fc.tar.gz
PeerTube-60650c77c8a2a98e92d869b237ae4900f369a8fc.tar.zst
PeerTube-60650c77c8a2a98e92d869b237ae4900f369a8fc.zip
Add scores to follows and remove bad ones
Diffstat (limited to 'server/lib/jobs')
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts10
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts9
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts8
3 files changed, 23 insertions, 4 deletions
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts
index c20a48a4e..3f780e319 100644
--- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts
+++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts
@@ -1,5 +1,6 @@
1import { logger } from '../../../helpers/logger' 1import { logger } from '../../../helpers/logger'
2import { doRequest } from '../../../helpers/requests' 2import { doRequest } from '../../../helpers/requests'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
3import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' 4import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
4 5
5async function process (payload: ActivityPubHttpPayload, jobId: number) { 6async function process (payload: ActivityPubHttpPayload, jobId: number) {
@@ -15,15 +16,22 @@ async function process (payload: ActivityPubHttpPayload, jobId: number) {
15 httpSignature: httpSignatureOptions 16 httpSignature: httpSignatureOptions
16 } 17 }
17 18
19 const badUrls: string[] = []
20 const goodUrls: string[] = []
21
18 for (const uri of payload.uris) { 22 for (const uri of payload.uris) {
19 options.uri = uri 23 options.uri = uri
20 24
21 try { 25 try {
22 await doRequest(options) 26 await doRequest(options)
27 goodUrls.push(uri)
23 } catch (err) { 28 } catch (err) {
24 await maybeRetryRequestLater(err, payload, uri) 29 const isRetryingLater = await maybeRetryRequestLater(err, payload, uri)
30 if (isRetryingLater === false) badUrls.push(uri)
25 } 31 }
26 } 32 }
33
34 return ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes(goodUrls, badUrls, undefined)
27} 35}
28 36
29function onError (err: Error, jobId: number) { 37function onError (err: Error, jobId: number) {
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 d576cd42e..884ede5a3 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,6 +4,7 @@ import { logger } from '../../../helpers/logger'
4import { getServerActor } from '../../../helpers/utils' 4import { getServerActor } from '../../../helpers/utils'
5import { ACTIVITY_PUB } from '../../../initializers' 5import { ACTIVITY_PUB } from '../../../initializers'
6import { ActorModel } from '../../../models/activitypub/actor' 6import { ActorModel } from '../../../models/activitypub/actor'
7import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
7import { JobHandler, JobScheduler } from '../job-scheduler' 8import { JobHandler, JobScheduler } from '../job-scheduler'
8 9
9import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler' 10import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler'
@@ -26,7 +27,7 @@ const jobCategory: JobCategory = 'activitypub-http'
26 27
27const activitypubHttpJobScheduler = new JobScheduler(jobCategory, jobHandlers) 28const activitypubHttpJobScheduler = new JobScheduler(jobCategory, jobHandlers)
28 29
29function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPayload, uri: string) { 30async function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPayload, uri: string) {
30 logger.warn('Cannot make request to %s.', uri, err) 31 logger.warn('Cannot make request to %s.', uri, err)
31 32
32 let attemptNumber = payload.attemptNumber || 1 33 let attemptNumber = payload.attemptNumber || 1
@@ -39,8 +40,12 @@ function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPayload, ur
39 uris: [ uri ], 40 uris: [ uri ],
40 attemptNumber 41 attemptNumber
41 }) 42 })
42 return activitypubHttpJobScheduler.createJob(undefined, 'activitypubHttpUnicastHandler', newPayload) 43 await activitypubHttpJobScheduler.createJob(undefined, 'activitypubHttpUnicastHandler', newPayload)
44
45 return true
43 } 46 }
47
48 return false
44} 49}
45 50
46async function computeBody (payload: ActivityPubHttpPayload) { 51async function computeBody (payload: ActivityPubHttpPayload) {
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
index 175ec6642..e02bd698e 100644
--- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
+++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
@@ -1,5 +1,6 @@
1import { logger } from '../../../helpers/logger' 1import { logger } from '../../../helpers/logger'
2import { doRequest } from '../../../helpers/requests' 2import { doRequest } from '../../../helpers/requests'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
3import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' 4import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
4 5
5async function process (payload: ActivityPubHttpPayload, jobId: number) { 6async function process (payload: ActivityPubHttpPayload, jobId: number) {
@@ -18,8 +19,13 @@ async function process (payload: ActivityPubHttpPayload, jobId: number) {
18 19
19 try { 20 try {
20 await doRequest(options) 21 await doRequest(options)
22 await ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([ uri ], [], undefined)
21 } catch (err) { 23 } catch (err) {
22 await maybeRetryRequestLater(err, payload, uri) 24 const isRetryingLater = await maybeRetryRequestLater(err, payload, uri)
25 if (isRetryingLater === false) {
26 await ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([], [ uri ], undefined)
27 }
28
23 throw err 29 throw err
24 } 30 }
25} 31}