コード例 #1
0
        private void DoTimer(object state)
        {
            lock (_sync)
            {
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
            }

            if (!_isStarted)
            {
                return;
            }

            try
            {
                if (_readAllRecordsCallback != null)
                {
                    var data = _readAllRecordsCallback.Invoke();

                    foreach (var group in data.GroupBy(e => e.PartitionKey))
                    {
                        _writer.CleanAndBulkInsertAsync(group.Key, group).GetAwaiter().GetResult();
                    }

                    _log.Info($"Reload MyNoSql table for entity {typeof(TEntity).Name}. Count Record: {data.Count}");
                }

                if (_maxInCache.HasValue)
                {
                    _writer.CleanAndKeepMaxPartitions(_maxInCache.Value).GetAwaiter().GetResult();
                    _log.Info($"Clear MyNoSql table for entity {typeof(TEntity).Name}. Max Record: {_maxInCache}");
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex, $"Cannot refresh data in MyNoSQL table. Entity: {typeof(TEntity).Name}");
            }

            lock (_sync)
            {
                if (_isStarted)
                {
                    _timer?.Change(_reloadTimerPeriod, _reloadTimerPeriod);
                }
            }
        }
コード例 #2
0
 public async Task CleanAndBulkInsertAsync(string partitionKey, IEnumerable <TEntity> list)
 {
     await _writer.CleanAndBulkInsertAsync(partitionKey, list);
 }