/// <summary>
        /// Checks access to log files and that they are written to every day
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation($"Health check {Startup.RollingStartNumberPattern}");

            var batchSize = 10;
            var query     = _httpContextAccessor.HttpContext.Request.Query;

            if (query.ContainsKey(QueryValue))
            {
                query.TryGetValue(QueryValue, out var values);
                batchSize = int.Parse(values.ToString());
            }

            var status = HealthStatus.Healthy;
            var data   = new Dictionary <string, object>();

            try
            {
                var temporaryExposureKeys = _temporaryExposureKeyRepository.GetAllKeysNextBatch(0, batchSize);
                foreach (var key in temporaryExposureKeys)
                {
                    var rollingStartNumber = key.RollingStartNumber;
                    var isMidnight         = IsMidnight(rollingStartNumber);
                    if (isMidnight)
                    {
                        continue;
                    }

                    status = HealthStatus.Unhealthy;
                    data.Add($"Entry {key.Id} rollingStartNumber not midnight", $"{rollingStartNumber}");
                }
            }
            catch (Exception e)
            {
                var errorMessage = $"{e.Message} - {e.StackTrace}";
                _logger.LogError(errorMessage);

                status = HealthStatus.Unhealthy;
                data.Add($"Error in data retrieval {DateTime.Now}", errorMessage);

                return(Task.FromResult(new HealthCheckResult(
                                           status,
                                           Description,
                                           e,
                                           data)));
            }

            return(Task.FromResult(new HealthCheckResult(
                                       status,
                                       Description,
                                       data: data)));
        }
Beispiel #2
0
        public void FindAndRemoveInvalidKeys(int batchSize)
        {
            int numberOfRecordsToSkip = 0;
            List <TemporaryExposureKey> databaseKeys;
            List <TemporaryExposureKey> wrongKeys = new List <TemporaryExposureKey>();
            var errorMessage = string.Empty;

            do
            {
                databaseKeys = _repository.GetAllKeysNextBatch(numberOfRecordsToSkip, batchSize).ToList();
                foreach (var key in databaseKeys)
                {
                    if (!_keyValidator.ValidateKeyAPI(key, out errorMessage))
                    {
                        wrongKeys.Add(key);
                    }
                }
                numberOfRecordsToSkip += databaseKeys.Count;
            }while (databaseKeys.Count > 0);

            _repository.RemoveKeys(wrongKeys);
            _logger.LogInformation($"Removed {wrongKeys.Count} invalid keys from the database: {JsonConvert.SerializeObject(wrongKeys)}");
        }