private async Task ProcessRegionLoopAsync(RegionInformation regionInformation, CancellationToken token) { using (_logger.BeginScope( "Starting search instance check loop for region {Region}, service {ServiceName}.", regionInformation.Region, regionInformation.ServiceName)) { var stopwatch = Stopwatch.StartNew(); do { try { _logger.LogInformation("Checking region {Region} for search instances that need rebooting.", regionInformation.Region); await ProcessRegionOnceAsync(regionInformation, token); _logger.LogInformation( "Sleeping for {SleepDuration} before checking region {Region} again.", _configuration.Value.SleepDuration, regionInformation.Region); } catch (Exception ex) { _logger.LogError( (EventId)0, ex, "An exception was thrown when processing region {Region}.", regionInformation.Region); } await Task.Delay(_configuration.Value.SleepDuration); }while (stopwatch.Elapsed < _configuration.Value.ProcessLifetime); } }
private static RegionInformation[] GetRegionInformations() { if (options != null && !options.IncludeRegionInformations) { return(null); } List <XElement> regionInformationElements = (from i in supplementalDataDocument.Elements("supplementalData") .Elements("territoryInfo").Elements("territory") select i).ToList(); if (regionInformationElements.Count == 0) { return(null); } List <RegionInformation> regionInformations = new List <RegionInformation>(); foreach (XElement regionInformationElement in regionInformationElements) { string regionInformationId = regionInformationElement.Attribute("type").Value.ToString(); Progress("Adding region information", regionInformationId); RegionInformation regionInformation = new RegionInformation(); regionInformation.Id = regionInformationId; regionInformation.Gdp = Int64.Parse(regionInformationElement.Attribute("gdp").Value.ToString()); regionInformation.LiteracyPercent = float.Parse(regionInformationElement.Attribute("literacyPercent").Value.ToString()); regionInformation.Population = (int)float.Parse(regionInformationElement.Attribute("population").Value.ToString()); List <LanguagePopulation> languagePopulations = new List <LanguagePopulation>(); foreach (XElement languagePopulationElement in regionInformationElement.Elements("languagePopulation")) { LanguagePopulation languagePopulation = new LanguagePopulation(); languagePopulation.Id = languagePopulationElement.Attribute("type").Value.ToString(); languagePopulation.PopulationPercent = float.Parse(languagePopulationElement.Attribute("populationPercent").Value.ToString()); if (languagePopulationElement.Attribute("references") != null) { languagePopulation.References = languagePopulationElement.Attribute("references").Value.ToString(); } if (languagePopulationElement.Attribute("officialStatus") != null) { languagePopulation.OfficialStatus = languagePopulationElement.Attribute("officialStatus").Value.ToString(); } languagePopulations.Add(languagePopulation); } regionInformation.LanguagePopulations = languagePopulations.ToArray(); regionInformations.Add(regionInformation); Progress("Added region information", regionInformationId, ProgressEventType.Added, regionInformation); } return(regionInformations.ToArray()); }
private async Task ProcessRegionOnceAsync(RegionInformation regionInformation, CancellationToken token) { var instances = await _searchServiceClient.GetSearchEndpointsAsync(regionInformation, token); var latestFeedTimeStamp = await _feedClient.GetLatestFeedTimeStampAsync(); _logger.LogDebug("The latest feed timestamp is {LastFeedTimeStamp}.", latestFeedTimeStamp); // Determine the health of all instances. var tasks = instances .Select(i => GetInstanceAndHealthAsync(latestFeedTimeStamp, i, token)) .ToList(); var instancesAndHealths = await Task.WhenAll(tasks); var healthyCount = instancesAndHealths.Count(x => x.Health == InstanceHealth.Healthy); var unhealthyCount = instancesAndHealths.Count(x => x.Health == InstanceHealth.Unhealthy); if (healthyCount == 0) { _logger.LogWarning( "There are no healthy instances on {Region}. No instances will be restarted since there is " + "likely a broader issue going on.", regionInformation.Region); } else if (unhealthyCount == 0) { _logger.LogInformation( "There are no unhealthy instances on {Region}. No more work is necessary.", regionInformation.Region); } else { // Restart the first unhealthy instance and wait for it to come back. var unhealthyInstance = instancesAndHealths .Where(i => i.Health == InstanceHealth.Unhealthy) .OrderBy(i => i.Instance.Index) .FirstOrDefault(); await RestartInstanceAndWaitForHealthyAsync( regionInformation, latestFeedTimeStamp, unhealthyInstance.Instance, token); } // Emit telemetry _telemetryService.TrackHealthyInstanceCount(regionInformation.Region, healthyCount); _telemetryService.TrackUnhealthyInstanceCount(regionInformation.Region, unhealthyCount); _telemetryService.TrackUnknownInstanceCount( regionInformation.Region, instancesAndHealths.Count(x => x.Health == InstanceHealth.Unknown)); _telemetryService.TrackInstanceCount( regionInformation.Region, instancesAndHealths.Count()); }
private async Task RestartInstanceAndWaitForHealthyAsync( RegionInformation regionInformation, DateTimeOffset latestFeedTimeStamp, Instance instance, CancellationToken token) { _telemetryService.TrackInstanceReboot(regionInformation.Region, instance.Index); var roleInstance = string.Format(_configuration.Value.RoleInstanceFormat, instance.Index); _logger.LogWarning("Rebooting role instance {RoleInstance} in region {Region}.", roleInstance, regionInformation.Region); await _azureManagementAPIWrapper.RebootCloudServiceRoleInstanceAsync( _configuration.Value.Subscription, regionInformation.ResourceGroup, regionInformation.ServiceName, instance.Slot, _configuration.Value.Role, roleInstance, token); InstanceHealth health; var waitStopwatch = Stopwatch.StartNew(); do { _logger.LogDebug( "Checking the health status of role instance {RoleInstance} after rebooting.", roleInstance); health = await DetermineInstanceHealthAsync(latestFeedTimeStamp, instance, token); if (health != InstanceHealth.Healthy) { await Task.Delay(_configuration.Value.InstancePollFrequency); } }while (waitStopwatch.Elapsed < _configuration.Value.WaitForHealthyDuration && health != InstanceHealth.Healthy); waitStopwatch.Stop(); _logger.LogInformation( "After waiting {WaitDuration}, instance {DiagUrl} has health of {Health}.", waitStopwatch.Elapsed, instance.DiagUrl, health); _telemetryService.TrackInstanceRebootDuration( regionInformation.Region, instance.Index, waitStopwatch.Elapsed, health); }
private void NationalitiesDashboardControl_Load(object sender, EventArgs e) { regionInformation = new RegionInformation(); Connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\anik\Documents\anik.mdf;Integrated Security=True;Connect Timeout=30"); dataShow(); }
public async Task <CommandResult> Pokedex(CommandContext context) { (Optional <User> optionalUser, Optional <string> optionalMode, Optional <User> optionalCompareUser) = await context.ParseArgs <Optional <User>, Optional <string>, Optional <User> >(); User user = optionalUser.OrElse(context.Message.User); bool isSelf = user == context.Message.User; if (!optionalMode.IsPresent) { int numUniqueSpecies = (await _badgeRepo.CountByUserPerSpecies(user.Id)).Count; return(new CommandResult { Response = isSelf ? $"You have collected {numUniqueSpecies} distinct Pokémon badge(s)" : $"{user.Name} has collected {numUniqueSpecies} distinct Pokémon badge(s)" }); } string mode = optionalMode.Value.ToLower(); ImmutableSortedDictionary <PkmnSpecies, int> numBadgesPerSpecies = await _badgeRepo.CountByUserPerSpecies(user.Id); if (mode.Equals(PokedexModeMissing)) { IEnumerable <PkmnSpecies> missingList = _knownSpecies.Except(numBadgesPerSpecies.Keys); IEnumerable <string> badgesFormatted = missingList.Select(entry => $"{entry}"); return(new CommandResult { Response = isSelf ? $"You are currently missing the following badge(s): {string.Join(", ", badgesFormatted)}" : $"{user.Name} is currently missing the following badge(s): {string.Join(", ", badgesFormatted)}", ResponseTarget = ResponseTarget.WhisperIfLong }); } else if (mode.Equals(PokedexModeDupes)) { var dupeList = numBadgesPerSpecies.Where(kvp => kvp.Value > 1).ToList(); if (!dupeList.Any()) { return(new CommandResult { Response = isSelf ? $"You do not own any duplicate Pokémon badges" : $"{user.Name} does not own any duplicate Pokémon badges" }); } IEnumerable <string> badgesFormatted = dupeList.Select(kvp => $"{kvp.Key}"); return(new CommandResult { Response = isSelf ? $"You are owning duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}" : $"{user.Name} owns duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}", ResponseTarget = ResponseTarget.WhisperIfLong }); } else if (mode.Equals(PokedexModeComplementFromDupes)) { if (!optionalCompareUser.IsPresent) { return(new CommandResult { Response = $"Mode {PokedexModeComplementFromDupes} requires a second user argument" }); } ImmutableSortedDictionary <PkmnSpecies, int> compareUser = await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id); var compareUserDupeList = compareUser.Where(kvp => kvp.Value > 1).Select(kvp => kvp.Key); var differenceList = compareUserDupeList.Except(numBadgesPerSpecies.Keys).ToList(); if (!differenceList.Any()) { return(new CommandResult { Response = $"{optionalCompareUser.Value.Name} does not own any duplicate Pokémon badges {user.Name} is missing" }); } IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}"); return(new CommandResult { Response = $"{optionalCompareUser.Value.Name} owns the following duplicate badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}", ResponseTarget = ResponseTarget.WhisperIfLong }); } else if (mode.Equals(PokedexModeComplementFrom)) { if (!optionalCompareUser.IsPresent) { return(new CommandResult { Response = $"Mode {PokedexModeComplementFrom} requires a second user argument" }); } ImmutableSortedDictionary <PkmnSpecies, int> compareUser = await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id); var differenceList = compareUser.Keys.Except(numBadgesPerSpecies.Keys).ToList(); if (!differenceList.Any()) { return(new CommandResult { Response = $"{optionalCompareUser.Value.Name} does not own any Pokémon badges {user.Name} is missing" }); } IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}"); return(new CommandResult { Response = $"{optionalCompareUser.Value.Name} owns the following badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}", ResponseTarget = ResponseTarget.WhisperIfLong }); } else if (_pokedexModeRegions.ContainsKey(mode)) { RegionInformation regionInformation = _pokedexModeRegions[mode]; ImmutableSortedDictionary <PkmnSpecies, int> ownedPokemons = (await _badgeRepo.CountByUserPerSpecies(user.Id)); int userOwnedRegionCount = mode.Equals(PokedexModeNational) ? ownedPokemons.Count(ownedPokemon => ownedPokemon.Key.GetGeneration() != regionInformation.Generation) : ownedPokemons.Count(ownedPokemon => ownedPokemon.Key.GetGeneration() == regionInformation.Generation); return(new CommandResult { Response = isSelf ? $"You have collected {userOwnedRegionCount}/{regionInformation.TotalRegionCount} " + $"distinct {mode[0].ToString().ToUpper() + mode[1..].ToLower()} badge(s)"
private void RegionAddEditForm_Load(object sender, EventArgs e) { Connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\anik\Documents\anik.mdf;Integrated Security=True;Connect Timeout=30"); regionInformation = new RegionInformation(); }