From e29981afadf1f7bc144021d30c0941f9ad50d735 Mon Sep 17 00:00:00 2001 From: Citrinate Date: Mon, 25 Mar 2024 10:22:25 -0400 Subject: [PATCH] Add backoff when updating booster info --- BoosterManager/Boosters/BoosterQueue.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/BoosterManager/Boosters/BoosterQueue.cs b/BoosterManager/Boosters/BoosterQueue.cs index 1a319b9..705e5c9 100644 --- a/BoosterManager/Boosters/BoosterQueue.cs +++ b/BoosterManager/Boosters/BoosterQueue.cs @@ -21,6 +21,7 @@ internal sealed class BoosterQueue : IDisposable { internal int BoosterDelay = 0; // Delay, in seconds, added to all booster crafts private readonly BoosterDatabase? BoosterDatabase; internal event Action? OnBoosterInfosUpdated; + private float BoosterInfosUpdateBackOffMultiplier = 1.0F; internal BoosterQueue(Bot bot, BoosterHandler boosterHandler) { Bot = bot; @@ -57,13 +58,16 @@ private async Task Run() { if (!await UpdateBoosterInfos().ConfigureAwait(false)) { Bot.ArchiLogger.LogGenericError(Strings.BoosterInfoUpdateFailed); - UpdateTimer(DateTime.Now.AddMinutes(1)); + UpdateTimer(DateTime.Now.AddMinutes(Math.Min(15, 1 * BoosterInfosUpdateBackOffMultiplier))); + BoosterInfosUpdateBackOffMultiplier += 0.5F; return; } Booster? booster = GetNextCraftableBooster(BoosterType.Any); if (booster == null) { + BoosterInfosUpdateBackOffMultiplier = 1.0F; + return; } @@ -71,11 +75,14 @@ private async Task Run() { if (booster.Info.Price > GetAvailableGems()) { BoosterHandler.PerpareStatusReport(String.Format(Strings.NotEnoughGems, String.Format("{0:N0}", GetGemsNeeded(BoosterType.Any, wasCrafted: false) - GetAvailableGems())), suppressDuplicateMessages: true); OnBoosterInfosUpdated += ForceUpdateBoosterInfos; - UpdateTimer(DateTime.Now.AddMinutes(GetNumBoosters(BoosterType.OneTime) > 0 ? 1 : 15)); + UpdateTimer(DateTime.Now.AddMinutes(Math.Min(15, (GetNumBoosters(BoosterType.OneTime) > 0 ? 1 : 15) * BoosterInfosUpdateBackOffMultiplier))); + BoosterInfosUpdateBackOffMultiplier += 0.5F; return; } + BoosterInfosUpdateBackOffMultiplier = 1.0F; + if (!await CraftBooster(booster).ConfigureAwait(false)) { Bot.ArchiLogger.LogGenericError(String.Format(Strings.BoosterCreationFailed, booster.GameID)); VerifyCraftBoosterError(booster); @@ -93,6 +100,8 @@ private async Task Run() { } } + BoosterInfosUpdateBackOffMultiplier = 1.0F; + DateTime nextBoosterTime = booster.GetAvailableAtTime(BoosterDelay); if (nextBoosterTime < DateTime.Now.AddSeconds(MinDelayBetweenBoosters)) { nextBoosterTime = DateTime.Now.AddSeconds(MinDelayBetweenBoosters);