Ejemplo n.º 1
0
        /// <inheritdoc />
        public async Task <FeedResponse <T> > ExecuteNextAsync(CancellationToken token = default)
        {
            Guid queryId = Guid.NewGuid();

            if (!_hasLoggedQuery)
            {
                _logger.LogQueryExecution(
                    queryId,
                    _queryContext.SqlQuerySpec,
                    _queryContext.FeedOptions?.PartitionKey?.ToString(),
                    _continuationToken,
                    _queryContext.FeedOptions?.MaxItemCount);
                _hasLoggedQuery = true;
            }

            try
            {
                FeedResponse <T> response = await _feedIterator.ReadNextAsync(token);

                _continuationToken = response.ContinuationToken;

                _logger.LogQueryExecutionResult(
                    queryId,
                    response.ActivityId,
                    response.RequestCharge,
                    response.ContinuationToken,
                    response.ETag,
                    response.Count);

                return(response);
            }
            catch (CosmosException ex)
            {
                // The SDK wraps exceptions we throw in handlers with a CosmosException.
                Exception fhirException = ex.InnerException as FhirException ?? ex.InnerException as MicrosoftHealthException;

                if (fhirException == null)
                {
                    _processor.ProcessErrorResponse(ex.StatusCode, ex.Headers, ex.Message);
                }

                _logger.LogQueryExecutionResult(
                    queryId,
                    ex.ActivityId,
                    ex.RequestCharge,
                    null,
                    null,
                    0,
                    fhirException ?? ex);

                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the request context with Cosmos DB info and updates response headers with the session token and request change values.
        /// </summary>
        /// <param name="responseMessage">The response message</param>
        public async Task ProcessResponse(ResponseMessage responseMessage)
        {
            var responseRequestCharge = responseMessage.Headers.RequestCharge;

            _queryLogger.LogQueryExecutionResult(
                responseMessage.Headers.ActivityId,
                responseMessage.Headers.RequestCharge,
                responseMessage.ContinuationToken == null ? null : "<nonempty>",
                int.TryParse(responseMessage.Headers["x-ms-item-count"], out var count) ? count : 0,
                double.TryParse(responseMessage.Headers["x-ms-request-duration-ms"], out var duration) ? duration : 0,
                responseMessage.Headers["x-ms-documentdb-partitionkeyrangeid"]);

            IFhirRequestContext fhirRequestContext = _fhirRequestContextAccessor.RequestContext;

            if (fhirRequestContext == null)
            {
                return;
            }

            var sessionToken = responseMessage.Headers.Session;

            if (!string.IsNullOrEmpty(sessionToken))
            {
                fhirRequestContext.ResponseHeaders[CosmosDbHeaders.SessionToken] = sessionToken;
            }

            if (fhirRequestContext.Properties.TryGetValue(Constants.CosmosDbResponseMessagesProperty, out object propertyValue))
            {
                // This is planted in FhirCosmosSearchService in order for us to relay the individual responses
                // back for analysis of the selectivity of the search.
                ((ConcurrentBag <ResponseMessage>)propertyValue).Add(responseMessage);
            }

            await AddRequestChargeToFhirRequestContext(responseRequestCharge, responseMessage.StatusCode);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public async Task <FeedResponse <T> > ExecuteNextAsync(CancellationToken token = default)
        {
            Guid queryId = Guid.NewGuid();

            _logger.LogQueryExecution(
                queryId,
                _queryContext.SqlQuerySpec,
                _queryContext.FeedOptions?.PartitionKey?.ToString(),
                _continuationToken,
                _queryContext.FeedOptions?.MaxItemCount);

            try
            {
                FeedResponse <T> response = await _feedIterator.ReadNextAsync(token);

                _continuationToken = response.ContinuationToken;

                _logger.LogQueryExecutionResult(
                    queryId,
                    response.ActivityId,
                    response.RequestCharge,
                    response.ContinuationToken,
                    response.ETag,
                    response.Count);

                return(response);
            }
            catch (CosmosException ex)
            {
                _logger.LogQueryExecutionResult(
                    queryId,
                    ex.ActivityId,
                    ex.RequestCharge,
                    null,
                    null,
                    0,
                    ex);

                throw;
            }
        }