private void LoadAll()
        {
            var flags    = new Dictionary <string, ItemDescriptor>();
            var segments = new Dictionary <string, ItemDescriptor>();

            foreach (var path in _paths)
            {
                try
                {
                    var content = _fileReader.ReadAllText(path);
                    var data    = _parser.Parse(content);
                    _dataMerger.AddToData(data, flags, segments);
                }
                catch (FileNotFoundException) when(_skipMissingPaths)
                {
                    _logger.Debug("{0}: {1}", path, "File not found");
                }
                catch (Exception e)
                {
                    LogHelpers.LogException(_logger, "Failed to load " + path, e);
                    return;
                }
            }
            var allData = new FullDataSet <ItemDescriptor>(
                ImmutableDictionary.Create <DataKind, KeyedItems <ItemDescriptor> >()
                .SetItem(DataModel.Features, new KeyedItems <ItemDescriptor>(flags))
                .SetItem(DataModel.Segments, new KeyedItems <ItemDescriptor>(segments))
                );

            _dataSourceUpdates.Init(allData);
            _loadedValidData = true;
        }
Пример #2
0
        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));
            }
        }
Пример #3
0
 public Task <bool> Start()
 {
     _dataSourceUpdates.Init(_data);
     return(Task.FromResult(true));
 }
Пример #4
0
 public Task <bool> Start()
 {
     _updates.Init(_parent.MakeInitData());
     _updates.UpdateStatus(DataSourceState.Valid, null);
     return(Task.FromResult(true));
 }