diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /server/lib/schedulers/actor-follow-scheduler.ts | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'server/lib/schedulers/actor-follow-scheduler.ts')
-rw-r--r-- | server/lib/schedulers/actor-follow-scheduler.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/server/lib/schedulers/actor-follow-scheduler.ts b/server/lib/schedulers/actor-follow-scheduler.ts new file mode 100644 index 000000000..3967be7f8 --- /dev/null +++ b/server/lib/schedulers/actor-follow-scheduler.ts | |||
@@ -0,0 +1,47 @@ | |||
1 | import { isTestInstance } from '../../helpers/core-utils' | ||
2 | import { logger } from '../../helpers/logger' | ||
3 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | ||
4 | import { AbstractScheduler } from './abstract-scheduler' | ||
5 | import { SCHEDULER_INTERVALS_MS } from '../../initializers' | ||
6 | import { ActorFollowScoreCache } from '../cache' | ||
7 | |||
8 | export class ActorFollowScheduler extends AbstractScheduler { | ||
9 | |||
10 | private static instance: AbstractScheduler | ||
11 | |||
12 | protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.actorFollowScores | ||
13 | |||
14 | private constructor () { | ||
15 | super() | ||
16 | } | ||
17 | |||
18 | protected async internalExecute () { | ||
19 | await this.processPendingScores() | ||
20 | |||
21 | await this.removeBadActorFollows() | ||
22 | } | ||
23 | |||
24 | private async processPendingScores () { | ||
25 | const pendingScores = ActorFollowScoreCache.Instance.getPendingFollowsScoreCopy() | ||
26 | |||
27 | ActorFollowScoreCache.Instance.clearPendingFollowsScore() | ||
28 | |||
29 | for (const inbox of Object.keys(pendingScores)) { | ||
30 | await ActorFollowModel.updateFollowScore(inbox, pendingScores[inbox]) | ||
31 | } | ||
32 | } | ||
33 | |||
34 | private async removeBadActorFollows () { | ||
35 | if (!isTestInstance()) logger.info('Removing bad actor follows (scheduler).') | ||
36 | |||
37 | try { | ||
38 | await ActorFollowModel.removeBadActorFollows() | ||
39 | } catch (err) { | ||
40 | logger.error('Error in bad actor follows scheduler.', { err }) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | static get Instance () { | ||
45 | return this.instance || (this.instance = new this()) | ||
46 | } | ||
47 | } | ||