aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers/actor-follow-scheduler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/schedulers/actor-follow-scheduler.ts')
-rw-r--r--server/lib/schedulers/actor-follow-scheduler.ts54
1 files changed, 0 insertions, 54 deletions
diff --git a/server/lib/schedulers/actor-follow-scheduler.ts b/server/lib/schedulers/actor-follow-scheduler.ts
deleted file mode 100644
index e1c56c135..000000000
--- a/server/lib/schedulers/actor-follow-scheduler.ts
+++ /dev/null
@@ -1,54 +0,0 @@
1import { isTestOrDevInstance } from '../../helpers/core-utils'
2import { logger } from '../../helpers/logger'
3import { ACTOR_FOLLOW_SCORE, SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
4import { ActorFollowModel } from '../../models/actor/actor-follow'
5import { ActorFollowHealthCache } from '../actor-follow-health-cache'
6import { AbstractScheduler } from './abstract-scheduler'
7
8export class ActorFollowScheduler extends AbstractScheduler {
9
10 private static instance: AbstractScheduler
11
12 protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES
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 = ActorFollowHealthCache.Instance.getPendingFollowsScore()
26 const badServerIds = ActorFollowHealthCache.Instance.getBadFollowingServerIds()
27 const goodServerIds = ActorFollowHealthCache.Instance.getGoodFollowingServerIds()
28
29 ActorFollowHealthCache.Instance.clearPendingFollowsScore()
30 ActorFollowHealthCache.Instance.clearBadFollowingServerIds()
31 ActorFollowHealthCache.Instance.clearGoodFollowingServerIds()
32
33 for (const inbox of Object.keys(pendingScores)) {
34 await ActorFollowModel.updateScore(inbox, pendingScores[inbox])
35 }
36
37 await ActorFollowModel.updateScoreByFollowingServers(badServerIds, ACTOR_FOLLOW_SCORE.PENALTY)
38 await ActorFollowModel.updateScoreByFollowingServers(goodServerIds, ACTOR_FOLLOW_SCORE.BONUS)
39 }
40
41 private async removeBadActorFollows () {
42 if (!isTestOrDevInstance()) logger.info('Removing bad actor follows (scheduler).')
43
44 try {
45 await ActorFollowModel.removeBadActorFollows()
46 } catch (err) {
47 logger.error('Error in bad actor follows scheduler.', { err })
48 }
49 }
50
51 static get Instance () {
52 return this.instance || (this.instance = new this())
53 }
54}