private async Task SaveStatusRecordInDb(string message) { try { var newOverviewData = JsonConvert.DeserializeObject <OverViewData>(message); OverViewData lastOverviewData = null; if (KafkaHelpers.LatestOverviewInfo != null) { lastOverviewData = JsonConvert.DeserializeObject <OverViewData>(KafkaHelpers.LatestOverviewInfo); } var containerIndex = 0; foreach (var newContainerState in newOverviewData.Containers) { var lastContainerState = lastOverviewData.Containers[containerIndex]; if (lastOverviewData == null || !newContainerState.Equals(lastContainerState)) // If the container is different { using (var scope = _services.CreateScope()) { var repo = scope.ServiceProvider.GetRequiredService <IContainerUpdateRepo>(); try { if (await repo.ServerExists(newOverviewData.Servername)) { await repo.AddStatusRecord(newOverviewData.Servername, newContainerState); } else { await repo.CreateServer(newOverviewData.Servername, newOverviewData.Containers); await repo.AddStatusRecord(newOverviewData.Servername, newContainerState); } } catch (ArgumentException ex) { _logger.LogError(ex.Message); } } } // TODO: If the change is worrisome (unhealthy, or down) send a notice to the dashboard interface containerIndex++; } SetOverviewTimer(newOverviewData.Servername, newOverviewData.Containers.ToList()); } catch (Newtonsoft.Json.JsonException) { _logger.LogError("Invalid data"); } catch (Exception ex) { _logger.LogError(ex.GetType().FullName); _logger.LogError(ex.Message); } }
public static OverViewData CreateOverViewData(IList <OverviewContainerData> containers = null) { OverViewData overViewData = new OverViewData { Servername = KafkaHelpers.Servername }; if (_processesToStart.Contains("commandserver")) // If command server is active on this container, provide the relevant topics { overViewData.CommandRequestTopic = KafkaHelpers.RequestTopic; overViewData.CommandResponseTopic = KafkaHelpers.ResponseTopic; } if (containers != null) { overViewData.Containers = containers; } return(overViewData); }