]>
Commit | Line | Data |
---|---|---|
6fdc553a | 1 | import { isTestInstance } from '../../helpers/core-utils' |
60650c77 C |
2 | import { logger } from '../../helpers/logger' |
3 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | |
4 | import { AbstractScheduler } from './abstract-scheduler' | |
74dc3bca | 5 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' |
d74d29ad | 6 | import { ActorFollowScoreCache } from '../files-cache' |
60650c77 | 7 | |
2f5c6b2f | 8 | export class ActorFollowScheduler extends AbstractScheduler { |
60650c77 C |
9 | |
10 | private static instance: AbstractScheduler | |
11 | ||
2f5c6b2f | 12 | protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.actorFollowScores |
2baea0c7 | 13 | |
60650c77 C |
14 | private constructor () { |
15 | super() | |
16 | } | |
17 | ||
2f5c6b2f C |
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 () { | |
6fdc553a | 35 | if (!isTestInstance()) logger.info('Removing bad actor follows (scheduler).') |
ea99d15f | 36 | |
60650c77 C |
37 | try { |
38 | await ActorFollowModel.removeBadActorFollows() | |
39 | } catch (err) { | |
d5b7d911 | 40 | logger.error('Error in bad actor follows scheduler.', { err }) |
60650c77 C |
41 | } |
42 | } | |
43 | ||
44 | static get Instance () { | |
45 | return this.instance || (this.instance = new this()) | |
46 | } | |
47 | } |