From 54a06fcf15f90a1feb490700a8fc8e1872222f6c Mon Sep 17 00:00:00 2001 From: updraft0 Date: Tue, 11 Jun 2024 12:01:08 +0100 Subject: [PATCH] chore(auth): tweak timings in the auth refresh process again --- .../server/tracking/CharacterAuthTracker.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/main/scala/org/updraft0/controltower/server/tracking/CharacterAuthTracker.scala b/server/src/main/scala/org/updraft0/controltower/server/tracking/CharacterAuthTracker.scala index 2297a90..7068d0d 100644 --- a/server/src/main/scala/org/updraft0/controltower/server/tracking/CharacterAuthTracker.scala +++ b/server/src/main/scala/org/updraft0/controltower/server/tracking/CharacterAuthTracker.scala @@ -17,6 +17,9 @@ object CharacterAuthTracker: // Every poll interval, refresh the tokens that need to be refreshed private val PollInterval = 20.seconds + // Multiplier of PollInterval to consider starting to refresh tokens before they expire + private val PollIntervalExpiryMultiplier = 4 + private val FailedRefreshInterval = 1.minute // Every snapshot interval, send out the current universe of auth tokens @@ -32,8 +35,6 @@ object CharacterAuthTracker: case Active(token: CharacterAuth) case RefreshFailure(prev: CharacterAuth, retryCount: Int, nextAt: Instant) -// private case class CharacterState(auth: Option[CharacterAuth], refreshFailureCount: Int) - def layer: ZLayer[Users.Env, Throwable, CharacterAuthTracker] = ZLayer.scoped(apply()) def apply() = @@ -67,7 +68,7 @@ object CharacterAuthTracker: ) = for now <- ZIO.clockWith(_.instant) - nowExp = now.plus(PollInterval.multipliedBy(2)) + nowExp = now.plus(PollInterval.multipliedBy(PollIntervalExpiryMultiplier)) curr <- state.get nextStates <- ZIO.foreachExec(curr.keys.zip(curr.values))(ExecutionStrategy.ParallelN(EsiParallel))((cId, cSt) => handleRefresh(cId, cSt, nowExp)