Example #1
0
        public async Task SynchronizeSplits(long targetChangeNumber)
        {
            try
            {
                if (targetChangeNumber <= _splitCache.GetChangeNumber())
                {
                    return;
                }

                var fetchOptions = new FetchOptions {
                    CacheControlHeaders = true
                };

                var result = await AttempSplitsSync(targetChangeNumber, fetchOptions, _onDemandFetchMaxRetries, _onDemandFetchRetryDelayMs, false);

                if (result.Success)
                {
                    await _segmentFetcher.FetchSegmentsIfNotExists(result.SegmentNames);

                    _log.Debug($"Refresh completed in {_onDemandFetchMaxRetries - result.RemainingAttempts} attempts.");

                    return;
                }

                fetchOptions.Till = targetChangeNumber;
                var withCDNBypassed = await AttempSplitsSync(targetChangeNumber, fetchOptions, OnDemandFetchBackoffMaxRetries, null, true);

                if (withCDNBypassed.Success)
                {
                    await _segmentFetcher.FetchSegmentsIfNotExists(withCDNBypassed.SegmentNames);

                    _log.Debug($"Refresh completed bypassing the CDN in {OnDemandFetchBackoffMaxRetries - withCDNBypassed.RemainingAttempts} attempts.");
                }
                else
                {
                    _log.Debug($"No changes fetched after {OnDemandFetchBackoffMaxRetries - withCDNBypassed.RemainingAttempts} attempts with CDN bypassed.");
                }
            }
            catch (Exception ex)
            {
                _log.Error($"Exception caught executing SynchronizeSplits. {targetChangeNumber}", ex);
            }
        }