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.UpdateSearchParameterStatus(_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}.");
                }
            }
        }
Example #2
0
        private async Task UpdateParametersAndCompleteJob(CancellationToken cancellationToken)
        {
            (bool success, string error) = await _reindexUtilities.UpdateSearchParameterStatus(_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);
            }
        }
Example #3
0
        private async Task UpdateParametersAndCompleteJob()
        {
            // here we check if all the resource types which are base types of the search parameter
            // were reindexed by this job.  If so, then we should mark the search parameters
            // as fully reindexed
            var fullyIndexedParamUris = new List <string>();
            var reindexedResourcesSet = new HashSet <string>(_reindexJobRecord.Resources);

            foreach (var searchParam in _reindexJobRecord.SearchParams)
            {
                var searchParamInfo = _supportedSearchParameterDefinitionManager.GetSearchParameter(searchParam);
                if (reindexedResourcesSet.IsSupersetOf(searchParamInfo.BaseResourceTypes))
                {
                    fullyIndexedParamUris.Add(searchParam);
                }
            }

            _logger.LogTrace("Completing reindex job. Updating the status of the fully indexed search parameters: '{paramUris}'", string.Join("', '", fullyIndexedParamUris));
            (bool success, string error) = await _reindexUtilities.UpdateSearchParameterStatus(fullyIndexedParamUris, _cancellationToken);

            if (success)
            {
                await MoveToFinalStatusAsync(OperationStatus.Completed);

                _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 MoveToFinalStatusAsync(OperationStatus.Failed);
            }
        }