private void StartDaemons(ISettingsProvider settingsProvider)
        {
            _dump = new AsyncPeriodicalAction(
                async() =>
            {
                if (!Directory.Exists(Path.GetDirectoryName(settingsProvider.StorageSettings.WeaponIndexPath)))
                {
                    Directory.CreateDirectory(settingsProvider.StorageSettings.WeaponIndexPath);
                }

                await File.WriteAllTextAsync(settingsProvider.StorageSettings.WeaponIndexPath,
                                             _itemByName.ToJson());
            }, exception => _log.Error(exception, "Can't dump index"),
                () => settingsProvider.StorageSettings.IndexDumpPeriod);
            _cleanup = new PeriodicalAction(() =>
            {
                foreach (var pair in _itemByName.ToArray())
                {
                    if (pair.Value.ExpireAt <= DateTime.UtcNow)
                    {
                        _itemByName.TryRemove(pair.Key, out _);
                    }
                }
            }, exception => _log.Error(exception, "can't cleanup"),
                                            () => _settingsProvider.StorageSettings.WeaponStorageCleanupPeriod
                                            );
            _dump.Start();
            _cleanup.Start();
        }
Example #2
0
        public DynamicThreadPoolTracker(
            Func <IConfigurationProvider, ThreadPoolSettings> settingsProvider,
            IConfigurationProvider configProvider,
            IVostokApplicationLimits limits,
            ILog log)
        {
            this.log              = log.ForContext <DynamicThreadPoolTracker>();
            this.configProvider   = configProvider;
            applicationLimits     = limits;
            this.settingsProvider = settingsProvider ?? throw new ArgumentNullException(nameof(settingsProvider));

            threadPoolUpdate = new PeriodicalAction(CheckAndUpdate, LogOnException, () => ChecksPeriod);
            threadPoolUpdate.Start();
        }
        private void StartDaemons(ISettingsProvider settingsProvider)
        {
            _cleanup = new PeriodicalAction(() =>
            {
                if (!Directory.Exists(StorageFolder))
                {
                    return;
                }

                foreach (var file in Directory.GetFiles(StorageFolder))
                {
                    if (File.GetCreationTimeUtc(file) - DateTime.UtcNow >= settingsProvider.StorageSettings.WeaponTTL)
                    {
                        File.Delete(file);
                    }
                }
            }, exception => _log.Error(exception, "can't cleanup"),
                                            () => _settingsProvider.StorageSettings.WeaponStorageCleanupPeriod
                                            );
            _cleanup.Start();
        }
 public PeriodicObservable(Func <T> valueProvider, TimeSpan period)
 {
     baseObservable = new CachingObservable <T>();
     updateAction   = new PeriodicalAction(() => baseObservable.Next(valueProvider()), _ => {}, () => period);
 }