protected bool IsDependencyAvailable() { try { return(_dependency.IsDependencyAvailable()); } catch (Exception ex) { _logger.LogError(ex, "Error while querying dependency '{0}'", _dependency.Name); return(false); } }
/// <summary> /// Waits until the dependency is available or the polling is cancelled (during source stop), /// then calls the AfterDependencyRunning method. Periodically logs during the dependency unavailable outage. /// </summary> public virtual void Reset() { // Atomically test and set _resetInProgress to 1 if it is not already 1. If oldValue != 0 then // some other thread beat us to the reset, so we yield to them. int oldValue = Interlocked.CompareExchange(ref this._resetInProgress, 1, 0); if (oldValue != 0) { return; } if (_cancellationTokenSource != null) { _cancellationTokenSource.Cancel(); _cancellationTokenSource = null; } if (_dependency.IsDependencyAvailable()) { try { AfterDependencyAvailable(); } catch (Exception e) { _logger?.LogError($"Error invoking AfterDependencyRunning when dependent {_dependency.Name} for source {Id} transitioned to available: {e.ToMinimized()}"); } finally { _resetInProgress = 0; } return; } _cancellationTokenSource = new CancellationTokenSource(); CancellationToken token = _cancellationTokenSource.Token; Task.Run(() => { PollForDependency(token); }, token); }