private async Task UpdateTaskAsync() { try { var allData = await _featureRequestor.GetAllDataAsync(); if (allData != null) { _featureStore.Init(allData.ToGenericDictionary()); //We can't use bool in CompareExchange because it is not a reference type. if (Interlocked.CompareExchange(ref _initialized, INITIALIZED, UNINITIALIZED) == 0) { _initTask.SetResult(true); Log.Info("Initialized LaunchDarkly Polling Processor."); } } } catch (AggregateException ex) { Log.ErrorFormat("Error Updating features: '{0}'", ex, Util.ExceptionMessage(ex.Flatten())); } catch (UnsuccessfulResponseException ex) { Log.Error(Util.HttpErrorMessage(ex.StatusCode, "polling request", "will retry")); if (!Util.IsHttpErrorRecoverable(ex.StatusCode)) { try { // if client is initializing, make it stop waiting _initTask.SetResult(true); } catch (InvalidOperationException) { // the task was already set - nothing more to do } ((IDisposable)this).Dispose(); } } catch (Exception ex) { Log.ErrorFormat("Error Updating features: '{0}'", ex, Util.ExceptionMessage(ex)); } }
public async Task GetAllUsesCorrectUriAndParsesResponseAsync() { _server.Given(Request.Create().UsingGet()) .RespondWith(Response.Create().WithStatusCode(200).WithBody(AllDataJson)); var result = await _requestor.GetAllDataAsync(); var req = GetLastRequest(); Assert.Equal("/sdk/latest-all", req.Path); Assert.Equal(1, result.Flags.Count); Assert.Equal(1, result.Flags["flag1"].Version); Assert.Equal(1, result.Segments.Count); Assert.Equal(2, result.Segments["seg1"].Version); }
private async Task UpdateTaskAsync() { try { var allData = await _featureRequestor.GetAllDataAsync(); if (allData != null) { _featureStore.Init(allData.ToGenericDictionary()); //We can't use bool in CompareExchange because it is not a reference type. if (Interlocked.CompareExchange(ref _initialized, INITIALIZED, UNINITIALIZED) == 0) { _initTask.SetResult(true); Log.Info("Initialized LaunchDarkly Polling Processor."); } } } catch (AggregateException ex) { Log.ErrorFormat("Error Updating features: '{0}'", ex, Util.ExceptionMessage(ex.Flatten())); } catch (FeatureRequestorUnsuccessfulResponseException ex) when(ex.StatusCode == 401) { Log.ErrorFormat("Error Updating features: '{0}'", Util.ExceptionMessage(ex)); Log.Error("Received 401 error, no further polling requests will be made since SDK key is invalid"); ((IDisposable)this).Dispose(); } catch (Exception ex) { Log.ErrorFormat("Error Updating features: '{0}'", ex, Util.ExceptionMessage(ex)); } }
private async Task UpdateTaskAsync() { _log.Info("Polling LaunchDarkly for feature flag updates"); try { var allData = await _featureRequestor.GetAllDataAsync(); if (allData is null) { // This means it was cached, and alreadyInited was true _dataSourceUpdates.UpdateStatus(DataSourceState.Valid, null); } else { if (_dataSourceUpdates.Init(allData.Value)) { _dataSourceUpdates.UpdateStatus(DataSourceState.Valid, null); if (!_initialized.GetAndSet(true)) { _initTask.SetResult(true); _log.Info("First polling request successful"); } } } } catch (UnsuccessfulResponseException ex) { _log.Error(HttpErrors.ErrorMessage(ex.StatusCode, "polling request", "will retry")); var errorInfo = DataSourceStatus.ErrorInfo.FromHttpError(ex.StatusCode); if (HttpErrors.IsRecoverable(ex.StatusCode)) { _dataSourceUpdates.UpdateStatus(DataSourceState.Interrupted, errorInfo); } else { _dataSourceUpdates.UpdateStatus(DataSourceState.Off, errorInfo); try { // if client is initializing, make it stop waiting _initTask.SetResult(true); } catch (InvalidOperationException) { // the task was already set - nothing more to do } ((IDisposable)this).Dispose(); } } catch (JsonReadException ex) { _log.Error("Polling request received malformed data: {0}", LogValues.ExceptionSummary(ex)); _dataSourceUpdates.UpdateStatus(DataSourceState.Interrupted, new DataSourceStatus.ErrorInfo { Kind = DataSourceStatus.ErrorKind.InvalidData, Time = DateTime.Now }); } catch (Exception ex) { Exception realEx = (ex is AggregateException ae) ? ae.Flatten() : ex; LogHelpers.LogException(_log, "Polling for feature flag updates failed", realEx); _dataSourceUpdates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromException(realEx)); } }