public async Task <PagedMessages <ArchivedMessage> > Handle(GetMessages request, CancellationToken cancellationToken) { ICosmosDbContainer messagesContainer = await _cosmosDbClient.GetContainer("messages"); IQueryable <ArchivedMessage> query = messagesContainer.GetByLinq <ArchivedMessage>(); query = ApplyFilters(query, request); query = query.OrderByDescending(m => m.MessageDate); int count = await messagesContainer.ResolveCount(query); query = ApplyPaging(query, request); CosmosDbResponse <IEnumerable <ArchivedMessage> > messages = await messagesContainer.ResolveWithStreamIterator(query); if (!messages.IsSuccessful) { throw new ApplicationException($"Error fetching messages: {messages.ErrorMessage}"); } return(new PagedMessages <ArchivedMessage>() { Messages = messages.Result, PageIndex = request.MessageFilters.PageIndex, PageSize = request.MessageFilters.PageSize, TotalRecords = count }); }
public async Task <IEnumerable <HealthCheckInfo> > Handle(GetHealthCheckInfo request, CancellationToken cancellationToken) { IList <HealthCheckInfo> healthCheckInfoList = new List <HealthCheckInfo>(); //Get the latest HealthCheck Requests from Cosmos DB ICosmosDbContainer messagesContainer = await _cosmosDbClient.GetContainer("messages"); IQueryable <ArchivedMessage> query = messagesContainer.GetByLinq <ArchivedMessage>(); query = query.Where(m => m.Message.MessageType == typeof(HealthCheckRequest).AssemblyQualifiedName) .OrderByDescending(m => m.MessageDate) .Take(12); // last hour CosmosDbResponse <IEnumerable <ArchivedMessage> > messages = await messagesContainer.ResolveWithStreamIterator(query); if (!messages.IsSuccessful) { throw new ApplicationException($"Error fetching messages: {messages.ErrorMessage}"); } foreach (var message in messages.Result) { var heathCheckRequest = message.Message as HealthCheckRequest; var healthCheckInfo = new HealthCheckInfo { HealthCheckRequest = heathCheckRequest }; //Search the HealthCheck Responses using the correlationId IEnumerable <ArchivedMessage> healthCheckResponses = await GetHealthCheckResponsesByCorrelationId(message.Message.CorrelationId); foreach (var response in healthCheckResponses) { HealthCheckResponse healthCheckResponse = (HealthCheckResponse)response.Message; healthCheckResponse.ResponseStatus = healthCheckResponse.AggregateTestResults(); MarkDelayedHealthyResponseAsWarning(healthCheckResponse, heathCheckRequest.MessageDate); healthCheckInfo.HealthCheckResponses.Add(healthCheckResponse); } AddErrorsForMissingServices(healthCheckInfo); AggregateResult(healthCheckInfo); healthCheckInfoList.Add(healthCheckInfo); } return(healthCheckInfoList); }
private async Task <IEnumerable <ArchivedMessage> > GetHealthCheckResponsesByCorrelationId(string correlationId) { ICosmosDbContainer messagesContainer = await _cosmosDbClient.GetContainer("messages"); IQueryable <ArchivedMessage> queryHealthCheckResponse = messagesContainer.GetByLinq <ArchivedMessage>(); queryHealthCheckResponse = queryHealthCheckResponse.Where(m => m.Message.MessageType == typeof(HealthCheckResponse).AssemblyQualifiedName && m.Message.CorrelationId == correlationId); CosmosDbResponse <IEnumerable <ArchivedMessage> > messages = await messagesContainer.ResolveWithStreamIterator(queryHealthCheckResponse); if (!messages.IsSuccessful) { throw new ApplicationException($"Error fetching messages: {messages.ErrorMessage}"); } return(messages.Result); }