From 7ca77111eaf28c62b96884770fc7ff0ab257cbe5 Mon Sep 17 00:00:00 2001 From: Sella-GH <147769367+Sella-GH@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:19:58 +0100 Subject: [PATCH] Change execution time of automatic checks to include a buffer --- CHANGELOG.md | 1 + .../Services/CronJobs/AzzyBotGlobalChecksJob.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c528b93a..64196cf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - File logging now shows the EventId properly instead of the event name to align with the console logging - You can now correctly force the check to determine if AzuraCast is offline - Some spelling mistakes were corrected +- Automatic checks getting executed correctly now when their time has come ## 2.2.1 - 2025-01-05 ### Dependencies diff --git a/src/AzzyBot.Bot/Services/CronJobs/AzzyBotGlobalChecksJob.cs b/src/AzzyBot.Bot/Services/CronJobs/AzzyBotGlobalChecksJob.cs index a8f3db12..dbd09680 100644 --- a/src/AzzyBot.Bot/Services/CronJobs/AzzyBotGlobalChecksJob.cs +++ b/src/AzzyBot.Bot/Services/CronJobs/AzzyBotGlobalChecksJob.cs @@ -37,18 +37,18 @@ public async Task RunAsync(IJobExecutionContext context, CancellationToken token IReadOnlyList guilds = await _dbActions.GetGuildsAsync(loadEverything: true); DateTimeOffset utcNow = DateTimeOffset.UtcNow; - if (utcNow - azzyBot.LastDatabaseCleanup >= TimeSpan.FromHours(24)) + if (utcNow - azzyBot.LastDatabaseCleanup >= TimeSpan.FromHours(23.85)) await _dbMaintenance.CleanupLeftoverGuildsAsync(_discordClient.Guilds); - if (utcNow - azzyBot.LastUpdateCheck >= TimeSpan.FromHours(6)) + if (utcNow - azzyBot.LastUpdateCheck >= TimeSpan.FromHours(5.85)) await _updater.CheckForAzzyUpdatesAsync(); - List guildsWorkingSet = [.. guilds.Where(g => utcNow - g.LastPermissionCheck >= TimeSpan.FromHours(12))]; + List guildsWorkingSet = [.. guilds.Where(g => utcNow - g.LastPermissionCheck >= TimeSpan.FromHours(11.85))]; _logger.GlobalTimerCheckForChannelPermissions(guildsWorkingSet.Count); if (guildsWorkingSet.Count is not 0) await _botService.CheckPermissionsAsync(guildsWorkingSet); - guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.Checks.ServerStatus is true && utcNow - g.AzuraCast.Checks.LastServerStatusCheck >= TimeSpan.FromMinutes(15))]; + guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.Checks.ServerStatus is true)]; _logger.GlobalTimerCheckForAzuraCastStatus(guildsWorkingSet.Count); if (guildsWorkingSet.Count is not 0) { @@ -60,7 +60,7 @@ public async Task RunAsync(IJobExecutionContext context, CancellationToken token // Get it just one more time to check if the instance is offline guilds = await _dbActions.GetGuildsAsync(loadEverything: true); - guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.IsOnline is true && utcNow - g.AzuraCast.Checks.LastServerStatusCheck >= TimeSpan.FromHours(12))]; + guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.IsOnline is true && utcNow - g.AzuraCast.Checks.LastServerStatusCheck >= TimeSpan.FromHours(11.85))]; _logger.GlobalTimerCheckForAzuraCastApi(guildsWorkingSet.Count); if (guildsWorkingSet.Count is not 0) { @@ -70,20 +70,20 @@ public async Task RunAsync(IJobExecutionContext context, CancellationToken token } } - guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.IsOnline is true && g.AzuraCast.Stations.Any(s => s.Checks.FileChanges && utcNow - s.Checks.LastFileChangesCheck >= TimeSpan.FromHours(1)))]; + guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.IsOnline is true && g.AzuraCast.Stations.Any(s => s.Checks.FileChanges && utcNow - s.Checks.LastFileChangesCheck >= TimeSpan.FromHours(0.85)))]; _logger.GlobalTimerCheckForAzuraCastFiles(guildsWorkingSet.Count); if (guildsWorkingSet.Count is not 0) { foreach (GuildEntity guild in guildsWorkingSet) { - foreach (AzuraCastStationEntity station in guild.AzuraCast!.Stations.Where(s => s.Checks.FileChanges && utcNow - s.Checks.LastFileChangesCheck >= TimeSpan.FromHours(1))) + foreach (AzuraCastStationEntity station in guild.AzuraCast!.Stations.Where(s => s.Checks.FileChanges && utcNow - s.Checks.LastFileChangesCheck >= TimeSpan.FromHours(0.85))) { await _azuraFileService.CheckForFileChangesAsync(station); } } } - guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.IsOnline is true && g.AzuraCast.Checks.Updates && utcNow - g.AzuraCast.Checks.LastUpdateCheck >= TimeSpan.FromHours(6))]; + guildsWorkingSet = [.. guilds.Where(g => g.AzuraCast?.IsOnline is true && g.AzuraCast.Checks.Updates && utcNow - g.AzuraCast.Checks.LastUpdateCheck >= TimeSpan.FromHours(5.85))]; _logger.GlobalTimerCheckForAzuraCastUpdates(guildsWorkingSet.Count); if (guildsWorkingSet.Count is not 0) {