protected override void OnMongoClientChanged(MongoClient newClient)
        {
            DatabaseOptions options = base.DatabaseOptions.CurrentValue;

            _groupConfigsCollection = newClient.GetDatabase(options.DatabaseName).GetCollection <GroupConfig>(options.GroupConfigsCollectionName);
            _batchInserter?.UpdateCollection(_groupConfigsCollection);
        }
Example #2
0
        protected override void OnMongoClientChanged(MongoClient newClient)
        {
            DatabaseOptions options = base.DatabaseOptions.CurrentValue;

            _usersDataCollection = newClient.GetDatabase(options.DatabaseName).GetCollection <UserData>(options.UsersDataCollectionName);
            _batchInserter?.UpdateCollection(_usersDataCollection);
        }
        private void RecreateBatchInserter()
        {
            // validate delay is valid
            TimeSpan delay = base.DatabaseOptions.CurrentValue.GroupConfigsBatchDelay;

            if (delay <= TimeSpan.Zero)
            {
                throw new ArgumentException("Batching delay must be greater than 0", nameof(base.DatabaseOptions.CurrentValue.GroupConfigsBatchDelay));
            }

            // flush existing inserter to not lose any changes
            if (_batchInserter != null)
            {
                _batchInserter.Flush();
            }
            _log?.LogDebug("Creating batch inserter for item type {ItemType} with delay of {Delay}", typeof(GroupConfig).Name, delay);
            _batchInserter = new MongoDelayedBatchInserter <uint, GroupConfig>(delay, _log);
            _batchInserter.UpdateCollection(_groupConfigsCollection);
        }