Пример #1
0
        public async Task ReloadContinuouslyAsync(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                _logger.LogInformation("Trying to reload the auxiliary data.");

                TimeSpan delay;
                try
                {
                    await _cache.TryLoadAsync(token);

                    delay = _options.Value.AuxiliaryDataReloadFrequency;
                }
                catch (Exception ex)
                {
                    _logger.LogError(0, ex, "An exception was thrown while reloading the auxiliary data.");

                    delay = _options.Value.AuxiliaryDataReloadFailureRetryFrequency;
                }

                if (token.IsCancellationRequested)
                {
                    return;
                }

                _logger.LogInformation(
                    "Waiting {Duration} before attempting to reload the auxiliary data again.",
                    delay);
                await _systemTime.Delay(delay, token);
            }
        }
Пример #2
0
        public async Task RefreshContinuouslyAsync(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                _logger.LogInformation("Trying to refresh the secrets.");

                TimeSpan delay;
                try
                {
                    await _factory.RefreshAsync(token);

                    delay       = _options.Value.SecretRefreshFrequency;
                    LastRefresh = DateTimeOffset.UtcNow;
                }
                catch (Exception ex)
                {
                    _logger.LogError(0, ex, "An exception was thrown while refreshing the secrets.");

                    delay = _options.Value.SecretRefreshFailureRetryFrequency;
                }

                if (token.IsCancellationRequested)
                {
                    return;
                }

                _logger.LogInformation(
                    "Waiting {Duration} before attempting to refresh the secrets again.",
                    delay);
                await _systemTime.Delay(delay, token);
            }
        }
Пример #3
0
        private async Task <int> PushIndexActionsAsync(
            ConcurrentBag <IdAndValue <IndexActions> > indexActionsToPush,
            Stopwatch timeSinceLastPush)
        {
            var elapsed = timeSinceLastPush.Elapsed;

            if (timeSinceLastPush.IsRunning && elapsed < _options.Value.MinPushPeriod)
            {
                var timeUntilNextPush = _options.Value.MinPushPeriod - elapsed;
                _logger.LogInformation(
                    "Waiting for {Duration} before continuing.",
                    timeUntilNextPush);
                await _systemTime.Delay(timeUntilNextPush);
            }

            /// Create a new batch pusher just for this operation. Note that we don't use the internal queue of the
            /// batch pusher for more than a single batch because we want to control exactly when batches are pushed to
            /// Azure Search so that we can observe the <see cref="Auxiliary2AzureSearchConfiguration.MinPushPeriod"/>
            /// configuration property.
            var batchPusher = _batchPusherFactory();

            _logger.LogInformation(
                "Pushing a batch of {IdCount} IDs and {DocumentCount} documents.",
                indexActionsToPush.Count,
                GetBatchSize(indexActionsToPush));

            while (indexActionsToPush.TryTake(out var indexActions))
            {
                batchPusher.EnqueueIndexActions(indexActions.Id, indexActions.Value);
            }

            // Note that this method can throw a storage exception if one of the version lists has been modified during
            // the execution of this job loop.
            await batchPusher.FinishAsync();

            // Restart the timer AFTER the push is completed to err on the side of caution.
            timeSinceLastPush.Restart();

            return(0);
        }