public ReindexJobTaskTests()
        {
            _cancellationToken = _cancellationTokenSource.Token;

            var job = CreateReindexJobRecord();

            _fhirOperationDataStore.UpdateReindexJobAsync(job, _weakETag, _cancellationToken).ReturnsForAnyArgs(new ReindexJobWrapper(job, _weakETag));

            _searchService.SearchForReindexAsync(
                Arg.Any <IReadOnlyList <Tuple <string, string> > >(),
                Arg.Any <string>(),
                true,
                Arg.Any <CancellationToken>()).
            Returns(new SearchResult(5, new List <Tuple <string, string> >()));

            _reindexJobTask = new ReindexJobTask(
                () => _fhirOperationDataStore.CreateMockScope(),
                Options.Create(_reindexJobConfiguration),
                () => _searchService.CreateMockScope(),
                SearchParameterFixtureData.SupportedSearchDefinitionManager,
                _reindexUtilities,
                NullLogger <ReindexJobTask> .Instance);

            _reindexUtilities.UpdateSearchParameters(Arg.Any <IReadOnlyCollection <string> >(), Arg.Any <CancellationToken>()).Returns(x => (true, null));
        }
Example #2
0
        private async Task CheckJobCompletionStatus(CancellationToken cancellationToken)
        {
            // If any query still in progress then we are not done
            if (_reindexJobRecord.QueryList.Where(q =>
                                                  q.Status == OperationStatus.Queued ||
                                                  q.Status == OperationStatus.Running).Any())
            {
                return;
            }
            else
            {
                // all queries marked as complete, reindex job is done, check success or failure
                if (_reindexJobRecord.QueryList.All(q => q.Status == OperationStatus.Completed))
                {
                    (bool success, string error) = await _reindexUtilities.UpdateSearchParameters(_reindexJobRecord.SearchParams, cancellationToken);

                    if (success)
                    {
                        await CompleteJobAsync(OperationStatus.Completed, cancellationToken);

                        _logger.LogInformation($"Reindex job successfully completed, id {_reindexJobRecord.Id}.");
                    }
                    else
                    {
                        var issue = new OperationOutcomeIssue(
                            OperationOutcomeConstants.IssueSeverity.Error,
                            OperationOutcomeConstants.IssueType.Exception,
                            error);
                        _reindexJobRecord.Error.Add(issue);
                        _logger.LogError(error);

                        await CompleteJobAsync(OperationStatus.Failed, cancellationToken);
                    }
                }
                else
                {
                    await CompleteJobAsync(OperationStatus.Failed, cancellationToken);

                    _logger.LogInformation($"Reindex job did not complete successfully, id: {_reindexJobRecord.Id}.");
                }
            }
        }