public async Task <bool> IsThrottledAsync() { var desiredRate = await _jobState.GetDesiredPackageEventRateAsync(); var recentGalleryEvents = await _gallery.CountEventsInPastHourAsync(); var recentRevalidations = await _packageState.CountRevalidationsEnqueuedInPastHourAsync(); var revalidationQuota = desiredRate - recentRevalidations - recentGalleryEvents; if (revalidationQuota <= 0) { _logger.LogInformation( "Throttling revalidations. Desired rate: {DesiredRate}, gallery events: {GalleryEvents}, recent revalidations: {RecentRevalidations}", desiredRate, recentGalleryEvents, recentRevalidations); return(true); } else { _logger.LogInformation( "Allowing revalidations. Desired rate: {DesiredRate}, gallery events: {GalleryEvents}, recent revalidations: {RecentRevalidations}", desiredRate, recentGalleryEvents, recentRevalidations); return(false); } }