示例#1
0
        public override HealthCheck Check()
        {
            var enabledProviders = _providerFactory.GetAvailableProviders();
            var backOffProviders = enabledProviders.Join(_providerStatusService.GetBlockedProviders(),
                                                         i => i.Definition.Id,
                                                         s => s.ProviderId,
                                                         (i, s) => new { Provider = i, Status = s })
                                   .Where(p => p.Status.InitialFailure.HasValue &&
                                          p.Status.InitialFailure.Value.After(
                                              DateTime.UtcNow.AddHours(-6)))
                                   .ToList();

            if (backOffProviders.Empty())
            {
                return(new HealthCheck(GetType()));
            }

            if (backOffProviders.Count == enabledProviders.Count)
            {
                return(new HealthCheck(GetType(),
                                       HealthCheckResult.Error,
                                       _localizationService.GetLocalizedString("ApplicationStatusCheckAllClientMessage"),
                                       "#applications-are-unavailable-due-to-failures"));
            }

            return(new HealthCheck(GetType(),
                                   HealthCheckResult.Warning,
                                   string.Format(_localizationService.GetLocalizedString("ApplicationStatusCheckSingleClientMessage"),
                                                 string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))),
                                   "#applications-are-unavailable-due-to-failures"));
        }
        private IEnumerable <IApplication> FilterBlockedApplications(IEnumerable <IApplication> applications)
        {
            var blockedApplications = _applicationStatusService.GetBlockedProviders().ToDictionary(v => v.ProviderId, v => v);

            foreach (var application in applications)
            {
                ApplicationStatus blockedApplicationStatus;
                if (blockedApplications.TryGetValue(application.Definition.Id, out blockedApplicationStatus))
                {
                    _logger.Debug("Temporarily ignoring application {0} till {1} due to recent failures.", application.Definition.Name, blockedApplicationStatus.DisabledTill.Value.ToLocalTime());
                    continue;
                }

                yield return(application);
            }
        }