private void FlushStore <T>(FixedConcurrentQueue <T> store) { var run = true; var records = new List <T>(); var count = 0; while (run) { while (run && count < BulkSize) { try { T item; if (store.TryDequeue(out item)) { records.Add(item); } else if (store.Count == 0) { run = false; } } catch { run = false; } count++; } try { if (records.Any()) { _restService.Persist(records); } else { run = false; } } catch { records.ForEach(store.Enqueue); run = false; } records = new List <T>(); count = 0; } }
private Reporter() { _metricStore = new FixedConcurrentQueue <Metric>(DefaultMaxLocalItems); _timer = new Timer(DefaultTimerIntevalSec * 1000); _timer.Elapsed += (sender, args) => { FlushStore(_metricStore); _timer.Start(); }; _timer.AutoReset = false; _timer.Start(); _restService = new RestPersistanceService( Constants.ApiKeyAppSettingName.GetSetting <string>(), Constants.Host); }