예제 #1
0
        private async Task DetectChanges()
        {
            // TODO -- need to put some retry & exception handling here.
            try
            {
                _current = await _detector.Detect(_token);

                if (_current.CurrentMark > 0)
                {
                    _tracker.MarkHighWater(_current.CurrentMark);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed while making the initial determination of the high water mark");
            }

            await Task.Delay(_settings.FastPollingTime, _token);

            while (!_token.IsCancellationRequested)
            {
                HighWaterStatistics statistics = null;
                try
                {
                    statistics = await _detector.Detect(_token);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Failed while trying to detect high water statistics");
                    await Task.Delay(_settings.SlowPollingTime, _token);

                    continue;
                }

                var status = statistics.InterpretStatus(_current);

                switch (status)
                {
                case HighWaterStatus.Changed:
                    await markProgress(statistics, _settings.FastPollingTime);

                    break;

                case HighWaterStatus.CaughtUp:
                    await markProgress(statistics, _settings.SlowPollingTime);

                    break;

                case HighWaterStatus.Stale:
                    var safeHarborTime = _current.Timestamp.Add(_settings.StaleSequenceThreshold);
                    var delayTime      = safeHarborTime.Subtract(statistics.Timestamp);
                    if (delayTime.TotalSeconds > 0)
                    {
                        await Task.Delay(delayTime, _token);
                    }

                    statistics = await _detector.DetectInSafeZone(safeHarborTime, _token);
                    await markProgress(statistics, _settings.FastPollingTime);

                    break;
                }
            }

            _logger.LogInformation("HighWaterAgent has detected a cancellation and has stopped polling");
        }
예제 #2
0
        private async Task DetectChanges()
        {
            if (!IsRunning)
            {
                return;
            }

            try
            {
                _current = await _detector.Detect(_token).ConfigureAwait(false);

                if (_current.CurrentMark > 0)
                {
                    _tracker.MarkHighWater(_current.CurrentMark);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed while making the initial determination of the high water mark");
            }

            await Task.Delay(_settings.FastPollingTime, _token).ConfigureAwait(false);

            while (!_token.IsCancellationRequested)
            {
                if (!IsRunning)
                {
                    break;
                }

                HighWaterStatistics statistics = null;
                try
                {
                    statistics = await _detector.Detect(_token).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Failed while trying to detect high water statistics");
                    await Task.Delay(_settings.SlowPollingTime, _token).ConfigureAwait(false);

                    continue;
                }

                var status = statistics.InterpretStatus(_current);

                switch (status)
                {
                case HighWaterStatus.Changed:
                    await markProgress(statistics, _settings.FastPollingTime).ConfigureAwait(false);

                    break;

                case HighWaterStatus.CaughtUp:
                    await markProgress(statistics, _settings.SlowPollingTime).ConfigureAwait(false);

                    break;

                case HighWaterStatus.Stale:
                    _logger.LogInformation("High Water agent is stale at {CurrentMark}", statistics.CurrentMark);

                    // This gives the high water detection a chance to allow the gaps to fill in
                    // before skipping to the safe harbor time
                    var safeHarborTime = _current.Timestamp.Add(_settings.StaleSequenceThreshold);
                    if (safeHarborTime > statistics.Timestamp)
                    {
                        await Task.Delay(_settings.SlowPollingTime, _token).ConfigureAwait(false);

                        continue;
                    }

                    _logger.LogInformation("High Water agent is stale after threshold of {DelayInSeconds} seconds, skipping gap to events marked after {SafeHarborTime}", _settings.StaleSequenceThreshold.TotalSeconds, safeHarborTime);


                    statistics = await _detector.DetectInSafeZone(_token).ConfigureAwait(false);
                    await markProgress(statistics, _settings.FastPollingTime).ConfigureAwait(false);

                    break;
                }
            }

            _logger.LogInformation("HighWaterAgent has detected a cancellation and has stopped polling");
        }