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); }
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))); } }