Пример #1
0
        public FeatureToggleRepository(
            UnleashConfig unleashConfig,
            IUnleashScheduledExecutor executor,
            IToggleFetcher toggleFetcher,
            IToggleBackupHandler toggleBackupHandler)
        {
            _toggleBackupHandler = toggleBackupHandler;
            _toggleFetcher       = toggleFetcher;

            _toggleCollection = toggleBackupHandler.Read();

            _executor = executor;
            _executor.SetInterval(s => UpdateToggles(s).Wait(), 0, unleashConfig.FetchTogglesInterval);
        }
Пример #2
0
 public void Write(ToggleCollection toggleCollection)
 {
     try
     {
         using (var writer = new StreamWriter(_backupFile))
         {
             var json = JsonConvert.SerializeObject(toggleCollection);
             writer.Write(JsonConvert.SerializeObject(toggleCollection));
         }
     }
     catch (IOException e)
     {
         Logger.WarnException("Unleash was unable to backup feature toggles to file: {}", e, _backupFile);
     }
 }
Пример #3
0
        private async Task <FeatureToggleResponse> GetToggleResponse(HttpResponseMessage response)
        {
            _etag = response.Headers.ETag?.Tag;
            var content = await response.Content.ReadAsStringAsync();

            var toggles = new ToggleCollection();

            try
            {
                toggles = JsonToggleParser.FromJson(content);
            }
            catch (Exception ex)
            {
                Logger.WarnException("received toggles failed", ex);
            }
            return(FeatureToggleResponse.Changed(toggles));
        }
Пример #4
0
        public async Task UpdateToggles(object state)
        {
            try
            {
                var response = await _toggleFetcher.FetchToggles();

                if (response.IsChanged)
                {
                    _toggleCollection = response.ToggleCollection;
                    _toggleBackupHandler.Write(response.ToggleCollection);
                }
            }
            catch (Exception e)
            {
                Logger.WarnException("Could not refresh feature toggles", e);
            }
        }
Пример #5
0
 private FeatureToggleResponse(StatusType status, ToggleCollection toggleCollection)
 {
     Status           = status;
     ToggleCollection = toggleCollection;
 }
Пример #6
0
 public static FeatureToggleResponse Changed(ToggleCollection toggleCollection) => new FeatureToggleResponse(StatusType.CHANGED, toggleCollection);