Fix: Improve cache stability and configuration consistency

Active Folder Exclusion Fixes:
- Exclude active cache folders in GetCachedFrameAsync, GetCachedFramesAsync, and GetAllCacheFoldersAsync
- Prevents TaskCanceledException when reading metadata from folders being written to
- Matches pattern used in GetCachedRadarAsync for consistency

Cache Configuration Fixes:
- Standardize default CacheExpirationMinutes to 12.5 (matches appsettings.json)
- Add cache configuration to ScrapingService (removes hardcoded values)
- Fix check interval calculation bug for intervals that don't divide 60 evenly
- Fix NextUpdateTime calculation to account for background check intervals
- Add configuration validation to all service constructors

All fixes verified - service running stably with 0 exceptions in recent logs
This commit is contained in:
2025-12-16 02:33:51 +10:00
parent ee5bffde88
commit d60706f625
5 changed files with 100 additions and 16 deletions
+27 -2
View File
@@ -4,6 +4,32 @@ namespace BomLocalService.Utilities;
public static class ResponseBuilder
{
/// <summary>
/// Calculates the next time the background cache management service will check for updates.
/// Rounds up to the next interval boundary within the current hour, or wraps to next hour if needed.
/// </summary>
public static DateTime CalculateNextServiceCheck(int checkIntervalMinutes)
{
var now = DateTime.UtcNow;
var currentMinute = now.Minute;
// Calculate how many complete intervals have elapsed this hour
var intervalsElapsed = currentMinute / checkIntervalMinutes;
// Next interval starts at (intervalsElapsed + 1) * checkIntervalMinutes
var nextIntervalStartMinute = (intervalsElapsed + 1) * checkIntervalMinutes;
// If next interval is beyond 60 minutes, wrap to next hour
if (nextIntervalStartMinute >= 60)
{
// Next check is at the start of next hour (00 minutes)
return now.Date.AddHours(now.Hour + 1).AddMinutes(0);
}
// Next check is within current hour
return now.Date.AddHours(now.Hour).AddMinutes(nextIntervalStartMinute);
}
/// <summary>
/// Creates a RadarResponse from a cache folder path, frames, and metadata
/// </summary>
@@ -44,8 +70,7 @@ public static class ResponseBuilder
// Calculate next background service check time (rounds up to next check interval)
var now = DateTime.UtcNow;
var minutesUntilNextCheck = cacheManagementCheckIntervalMinutes - (now.Minute % cacheManagementCheckIntervalMinutes);
var nextServiceCheck = now.AddMinutes(minutesUntilNextCheck);
var nextServiceCheck = CalculateNextServiceCheck(cacheManagementCheckIntervalMinutes);
if (isUpdating)
{