Skip to content

Commit

Permalink
Change execution time of automatic checks to include a buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sella-GH committed Jan 7, 2025
1 parent 4f821b3 commit 7ca7711
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/AzzyBot.Bot/Services/CronJobs/AzzyBotGlobalChecksJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ public async Task RunAsync(IJobExecutionContext context, CancellationToken token
IReadOnlyList<GuildEntity> 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<GuildEntity> guildsWorkingSet = [.. guilds.Where(g => utcNow - g.LastPermissionCheck >= TimeSpan.FromHours(12))];
List<GuildEntity> 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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit 7ca7711

Please sign in to comment.