Skip to content

Commit

Permalink
chore(auth): tweak timings in the auth refresh process again
Browse files Browse the repository at this point in the history
  • Loading branch information
updraft0 committed Jun 11, 2024
1 parent 6551cd3 commit 54a06fc
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() =
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 54a06fc

Please sign in to comment.