private async Task NotifyFailureIfIsConfigured(LivenessConfiguration item, string content) { _logger.LogWarning($"LivenessRuner notify liveness failure for {item.LivenessUri}."); var lastNotification = _context.LivenessFailuresNotifications .Where(lf => lf.LivenessName.Equals(item.LivenessName, StringComparison.InvariantCultureIgnoreCase)) .OrderByDescending(lf => lf.LastNotified) .Take(1) .SingleOrDefault(); if (lastNotification != null && (DateTime.UtcNow - lastNotification.LastNotified).Seconds < _settings.MinimunSecondsBetweenFailureNotifications) { _logger.LogInformation("Notification is not performed becaused is already notified and the elapsed time is less than configured."); } else { await _failureNotifier.NotifyFailure(item.LivenessName, content); var notification = new LivenessFailureNotification() { LivenessName = item.LivenessName, LastNotified = DateTime.UtcNow }; await SaveNotification(notification); _logger.LogWarning("A new notification failure is created and sent."); } }
private async Task SaveNotification(LivenessFailureNotification notification) { if (notification != null) { await _db.LivenessFailuresNotifications.AddAsync(notification); await _db.SaveChangesAsync(); } }