Ejemplo n.º 1
0
        private async Task <SearchResult> ExecuteReindexQueryAsync(ReindexJobQueryStatus queryStatus, bool countOnly, CancellationToken cancellationToken)
        {
            var queryParametersList = new List <Tuple <string, string> >()
            {
                Tuple.Create(KnownQueryParameterNames.Count, _throttleController.GetThrottleBatchSize().ToString(CultureInfo.InvariantCulture)),
                Tuple.Create(KnownQueryParameterNames.Type, queryStatus.ResourceType),
            };

            if (queryStatus.ContinuationToken != null)
            {
                queryParametersList.Add(Tuple.Create(KnownQueryParameterNames.ContinuationToken, queryStatus.ContinuationToken));
            }

            if (!_reindexJobRecord.ResourceTypeSearchParameterHashMap.TryGetValue(queryStatus.ResourceType, out string searchParameterHash))
            {
                searchParameterHash = string.Empty;
            }

            using (IScoped <ISearchService> searchService = _searchServiceFactory())
            {
                try
                {
                    return(await searchService.Value.SearchForReindexAsync(queryParametersList, searchParameterHash, countOnly, cancellationToken));
                }
                catch (Exception ex)
                {
                    var message             = $"Error running reindex query for resource type {queryStatus.ResourceType}.";
                    var reindexJobException = new ReindexJobException(message, ex);
                    _logger.LogError(ex, message);
                    queryStatus.Error = reindexJobException.Message + " : " + ex.Message;

                    throw reindexJobException;
                }
            }
        }
Ejemplo n.º 2
0
        public async Task InitializeAsync()
        {
            _fhirOperationDataStore   = _fixture.OperationDataStore;
            _fhirStorageTestHelper    = _fixture.TestHelper;
            _scopedOperationDataStore = _fhirOperationDataStore.CreateMockScope();
            _scopedDataStore          = _fixture.DataStore.CreateMockScope();

            _jobConfiguration = new ReindexJobConfiguration();
            IOptions <ReindexJobConfiguration> optionsReindexConfig = Substitute.For <IOptions <ReindexJobConfiguration> >();

            optionsReindexConfig.Value.Returns(_jobConfiguration);

            _searchParameterDefinitionManager          = _fixture.SearchParameterDefinitionManager;
            _supportedSearchParameterDefinitionManager = _fixture.SupportedSearchParameterDefinitionManager;

            ResourceWrapperFactory wrapperFactory = Mock.TypeWithArguments <ResourceWrapperFactory>(
                new RawResourceFactory(new FhirJsonSerializer()),
                new FhirRequestContextAccessor(),
                _searchIndexer,
                _searchParameterDefinitionManager,
                Deserializers.ResourceDeserializer);

            _searchParameterStatusManager = _fixture.SearchParameterStatusManager;

            _createReindexRequestHandler = new CreateReindexRequestHandler(
                _fhirOperationDataStore,
                DisabledFhirAuthorizationService.Instance,
                optionsReindexConfig,
                _searchParameterDefinitionManager,
                _searchParameterOperations);

            _reindexUtilities = new ReindexUtilities(
                () => _scopedDataStore,
                _searchIndexer,
                Deserializers.ResourceDeserializer,
                _supportedSearchParameterDefinitionManager,
                _searchParameterStatusManager,
                wrapperFactory);

            _searchService = _fixture.SearchService.CreateMockScope();

            await _fhirStorageTestHelper.DeleteAllReindexJobRecordsAsync(CancellationToken.None);

            _throttleController.GetThrottleBasedDelay().Returns(0);
            _throttleController.GetThrottleBatchSize().Returns(100U);
        }