コード例 #1
0
        public UnleashServices(UnleashSettings settings, IRandom random, IUnleashApiClientFactory unleashApiClientFactory,
                               IUnleashScheduledTaskManager scheduledTaskManager, IToggleCollectionCache toggleCollectionCache,
                               IEnumerable <IStrategy> strategies)
        {
            this.Random = random ?? throw new ArgumentNullException(nameof(random));

            this.scheduledTaskManager = scheduledTaskManager ?? throw new ArgumentNullException(nameof(scheduledTaskManager));

            var settingsValidator = new UnleashSettingsValidator();

            settingsValidator.Validate(settings);

            StrategyMap = BuildStrategyMap(strategies?.ToArray() ?? new IStrategy[0]);

            CancellationToken = cancellationTokenSource.Token;

            var cachedFilesResult = toggleCollectionCache.Load(cancellationTokenSource.Token).GetAwaiter().GetResult();

            cacheMiss = cachedFilesResult.IsCacheMiss;


            ToggleCollection = new ThreadSafeToggleCollection
            {
                Instance = cachedFilesResult.InitialToggleCollection ?? new ToggleCollection()
            };

            MetricsBucket = new ThreadSafeMetricsBucket();

            var scheduledTasks = CreateScheduledTasks(settings, unleashApiClientFactory, toggleCollectionCache, cachedFilesResult);

            scheduledTaskManager.Configure(scheduledTasks, CancellationToken);
        }
コード例 #2
0
 public ClientRegistrationBackgroundTask(
     IUnleashApiClientFactory apiClientFactory,
     UnleashSettings settings,
     List <string> strategies)
 {
     this.apiClientFactory = apiClientFactory;
     this.settings         = settings;
     this.strategies       = strategies;
 }
コード例 #3
0
 public ClientMetricsBackgroundTask(
     IUnleashApiClientFactory apiClientFactory,
     UnleashSettings settings,
     ThreadSafeMetricsBucket metricsBucket)
 {
     this.apiClientFactory = apiClientFactory;
     this.settings         = settings;
     this.metricsBucket    = metricsBucket;
 }
コード例 #4
0
 public FetchFeatureTogglesTask(
     IUnleashApiClientFactory apiClientFactory,
     ThreadSafeToggleCollection toggleCollection,
     IToggleCollectionCache toggleCollectionCache,
     TaskCompletionSource <object> initializationTaskCompletionSource)
 {
     this.apiClientFactory      = apiClientFactory;
     this.toggleCollection      = toggleCollection;
     this.toggleCollectionCache = toggleCollectionCache;
     this.initializationTaskCompletionSource = initializationTaskCompletionSource;
 }
コード例 #5
0
        private IEnumerable <IUnleashScheduledTask> CreateScheduledTasks(UnleashSettings settings,
                                                                         IUnleashApiClientFactory unleashApiClientFactory, IToggleCollectionCache toggleCollectionCache,
                                                                         ToggleCollectionCacheResult toggleCollectionCacheResult)
        {
            yield return(new FetchFeatureTogglesTask(
                             unleashApiClientFactory,
                             ToggleCollection,
                             toggleCollectionCache,
                             flagsFetchedFromUnleashTaskCompletionSource)
            {
                ExecuteDuringStartup = true,
                Interval = settings.FetchTogglesInterval,
                Etag = toggleCollectionCacheResult.InitialETag
            });

            if (settings.RegisterClient)
            {
                yield return(new ClientRegistrationBackgroundTask(
                                 unleashApiClientFactory,
                                 settings,
                                 StrategyMap.Keys.ToList())
                {
                    Interval = TimeSpan.Zero,
                    ExecuteDuringStartup = true
                });
            }

            if (settings.SendMetricsInterval != null)
            {
                yield return(new ClientMetricsBackgroundTask(
                                 unleashApiClientFactory,
                                 settings,
                                 MetricsBucket)
                {
                    ExecuteDuringStartup = false,
                    Interval = settings.SendMetricsInterval.Value
                });
            }
        }