diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-25 15:05:18 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-25 18:41:17 +0100 |
commit | 94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4 (patch) | |
tree | 32a9148e0e4567f0c4ffae0412cbed20b84e8873 /server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts | |
parent | d765fafc3faf0db9818eb1a07161df1cb1bc0efa (diff) | |
download | PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.tar.gz PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.tar.zst PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.zip |
Move job queue to redis
We'll use it as cache in the future.
/!\ You'll loose your old jobs (pending jobs too) so upgrade only when
you don't have pending job anymore.
Diffstat (limited to 'server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts')
-rw-r--r-- | server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts | 50 |
1 files changed, 0 insertions, 50 deletions
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 deleted file mode 100644 index 54a7504e8..000000000 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | import { logger } from '../../../helpers/logger' | ||
2 | import { doRequest } from '../../../helpers/requests' | ||
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | ||
4 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' | ||
5 | |||
6 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | ||
7 | logger.info('Processing ActivityPub unicast in job %d.', jobId) | ||
8 | |||
9 | const uri = payload.uris[0] | ||
10 | |||
11 | const body = await computeBody(payload) | ||
12 | const httpSignatureOptions = await buildSignedRequestOptions(payload) | ||
13 | |||
14 | const options = { | ||
15 | method: 'POST', | ||
16 | uri, | ||
17 | json: body, | ||
18 | httpSignature: httpSignatureOptions | ||
19 | } | ||
20 | |||
21 | try { | ||
22 | await doRequest(options) | ||
23 | ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([ uri ], [], undefined) | ||
24 | } catch (err) { | ||
25 | const isRetryingLater = await maybeRetryRequestLater(err, payload, uri) | ||
26 | if (isRetryingLater === false) { | ||
27 | ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([], [ uri ], undefined) | ||
28 | } | ||
29 | |||
30 | throw err | ||
31 | } | ||
32 | } | ||
33 | |||
34 | function onError (err: Error, jobId: number) { | ||
35 | logger.error('Error when sending ActivityPub request in job %d.', jobId, err) | ||
36 | return Promise.resolve() | ||
37 | } | ||
38 | |||
39 | function onSuccess (jobId: number) { | ||
40 | logger.info('Job %d is a success.', jobId) | ||
41 | return Promise.resolve() | ||
42 | } | ||
43 | |||
44 | // --------------------------------------------------------------------------- | ||
45 | |||
46 | export { | ||
47 | process, | ||
48 | onError, | ||
49 | onSuccess | ||
50 | } | ||