public async Task <HealthCheckResult> CheckHealthAsync(
            HealthCheckContext context,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var healthCheckResultHealthy = true;

            try
            {
                var result = await _postCodeService.GetFromPostCode("SW1A 1AA"); // Buckingham Palace

                if (result.ResponseCode == LocationLookupResponse.ServerError)
                {
                    healthCheckResultHealthy = false;
                }
            }
            catch
            {
                healthCheckResultHealthy = false;
            }

            if (healthCheckResultHealthy)
            {
                return(HealthCheckResult.Healthy());
            }

            return(HealthCheckResult.Unhealthy());
        }
Ejemplo n.º 2
0
        public async Task <VacancySearchResult> GetByPostcode(string postcode, int distance)
        {
            var coordinates = await _geocodeService.GetFromPostCode(postcode);

            if (coordinates.ResponseCode == "OK")
            {
                var searchResults = new VacancySearchResult
                {
                    searchLocation = new Location()
                    {
                        Latitude = coordinates.Coordinates.Lat, Longitude = coordinates.Coordinates.Lon
                    }
                };

                var pageNumber     = 1;
                var vacancyApiList = GetVacancyList(distance, coordinates, pageNumber);

                while (vacancyApiList.Count == _apiMaxPageSize && vacancyApiList.Max(s => s.DistanceInMiles < distance))
                {
                    pageNumber++;

                    var list = GetVacancyList(distance, coordinates, pageNumber);
                    vacancyApiList.AddRange(list);

                    if (list.Count < _apiMaxPageSize)
                    {
                        break;
                    }
                }

                searchResults.Results = vacancyApiList.Where(w => w.TrainingType == TrainingType.Standard)
                                        .Select(_vacanciesMapper.Map)
                                        .ToList();

                Parallel.ForEach(searchResults.Results,
                                 vacancy => { vacancy.StaticMapUrl = _mappingService.GetStaticMapsUrl(vacancy.Location); });

                return(searchResults);
            }

            return(null);
        }