public async Task WhenAzureMessageQueueExists_ThenAzureMessageQueueIsHealthy() { A.CallTo(() => fakeSalesCatalogueStorageService.GetStorageAccountConnectionString(string.Empty, string.Empty)).Returns(GetStorageAccountConnectionStringAndContainerName().Item1); A.CallTo(() => fakeAzureMessageQueueHelperClient.CheckMessageQueueHealth(A <string> .Ignored, A <string> .Ignored)).Returns(new HealthCheckResult(HealthStatus.Healthy, "Azure message queue is healthy")); A.CallTo(() => fakeAzureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(A <ExchangeSetType> .Ignored)).Returns(1); var response = await azureMessageQueueHealthCheck.CheckHealthAsync(new HealthCheckContext()); Assert.AreEqual(HealthStatus.Healthy, response.Status); }
public async Task WhenAzureWebJobStatusIsNotRunning_ThenReturnUnhealthy() { A.CallTo(() => fakeAzureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(A <ExchangeSetType> .Ignored)).Returns(1); A.CallTo(() => fakeAzureWebJobsHealthCheckClient.CheckAllWebJobsHealth(A <List <WebJobDetails> > .Ignored)) .Returns(new HealthCheckResult(HealthStatus.Unhealthy, "Azure message queue is unhealthy")); var response = await azureWebJobsHealthCheckService.CheckHealthAsync(); Assert.AreEqual(HealthStatus.Unhealthy, response.Status); }
private async Task <HealthCheckResult> CheckAllMessageQueuesHealth() { string[] exchangeSetTypes = essFulfilmentStorageConfiguration.Value.ExchangeSetTypes.Split(","); string storageAccountConnectionString, queueName = string.Empty; HealthCheckResult messageQueueHealthStatus = new HealthCheckResult(HealthStatus.Healthy, "Azure message queue is healthy"); foreach (string exchangeSetTypeName in exchangeSetTypes) { Enum.TryParse(exchangeSetTypeName, out ExchangeSetType exchangeSetType); for (int i = 1; i <= azureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(exchangeSetType); i++) { queueName = string.Format(essFulfilmentStorageConfiguration.Value.DynamicQueueName, i); var storageAccountWithKey = azureBlobStorageService.GetStorageAccountNameAndKeyBasedOnExchangeSetType(exchangeSetType); storageAccountConnectionString = scsStorageService.GetStorageAccountConnectionString(storageAccountWithKey.Item1, storageAccountWithKey.Item2); messageQueueHealthStatus = await azureMessageQueueHelper.CheckMessageQueueHealth(storageAccountConnectionString, queueName); if (messageQueueHealthStatus.Status == HealthStatus.Unhealthy) { logger.LogError(EventIds.AzureMessageQueueIsUnhealthy.ToEventId(), messageQueueHealthStatus.Exception, "Azure message queue {queueName} is unhealthy", queueName); return(messageQueueHealthStatus); } } } logger.LogDebug(EventIds.AzureMessageQueueIsHealthy.ToEventId(), "Azure message queue is healthy"); return(messageQueueHealthStatus); }
public async Task <HealthCheckResult> CheckHealthAsync(CancellationToken cancellationToken = default) { try { string webJobUri, userNameKey, passwordKey = string.Empty; string[] exchangeSetTypes = essFulfilmentStorageConfiguration.Value.ExchangeSetTypes.Split(","); List <WebJobDetails> webJobs = new List <WebJobDetails>(); foreach (string exchangeSetTypeName in exchangeSetTypes) { Enum.TryParse(exchangeSetTypeName, out ExchangeSetType exchangeSetType); for (int instance = 1; instance <= azureBlobStorageService.GetInstanceCountBasedOnExchangeSetType(exchangeSetType); instance++) { userNameKey = $"ess-{webHostEnvironment.EnvironmentName}-{exchangeSetType}-{instance}-webapp-scm-username"; passwordKey = $"ess-{webHostEnvironment.EnvironmentName}-{exchangeSetType}-{instance}-webapp-scm-password"; webJobUri = $"https://ess-{webHostEnvironment.EnvironmentName}-{exchangeSetType}-{instance}-webapp.scm.azurewebsites.net/api/continuouswebjobs/ESSFulfilmentWebJob"; string userPassword = webJobsAccessKeyProvider.GetWebJobsAccessKey(userNameKey) + ":" + webJobsAccessKeyProvider.GetWebJobsAccessKey(passwordKey); userPassword = Convert.ToBase64String(Encoding.Default.GetBytes(userPassword)); WebJobDetails webJobDetails = new WebJobDetails { UserPassword = userPassword, WebJobUri = webJobUri, ExchangeSetType = exchangeSetTypeName, Instance = instance }; webJobs.Add(webJobDetails); } } var webJobsHealth = azureWebJobsHealthCheckClient.CheckAllWebJobsHealth(webJobs); await Task.WhenAll(webJobsHealth); return(webJobsHealth.Result); } catch (Exception ex) { return(HealthCheckResult.Unhealthy("Azure webjob is unhealthy", new Exception(ex.Message))); } }