private async Task updateCache1(DbActions.UploadCpmsInfluxDb instance) { if (!cpmCacheDict.ContainsKey(instance.MachineCode)) { cpmCacheDict[instance.MachineCode] = new CpmCache(1024); } var cache = cpmCacheDict[instance.MachineCode]; //缓存 foreach (var cpm in instance.Cpms) { cache.Add(cpm); } //上传周期同与mq保持一致 if ((DateTime.Now - cache.LastUploadTime).TotalMilliseconds > HmiConfig.UploadWebBoardInterval || cache.DataCount > 900) { await Task.Run(() => { var upCaches = cache.Caches; var upCount = cache.DataCount; cache.Clear(); cache.LastUploadTime = DateTime.Now; bool success = InfluxDbHelper.GetInfluxDbService().WriteCpms(instance.MachineCode, upCaches, 0, upCount); if (success) { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbSuccess()); } else { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbFailed()); } }); } }
/// <summary> /// 刷新缓存到 influxDb /// </summary> /// <param name="instance"></param> async void updateCache2(DbActions.UploadCpmsInfluxDb instance) { try { if (!cpmCache2Dict.ContainsKey(instance.MachineCode)) { cpmCache2Dict[instance.MachineCode] = new CpmCache2(128); } var cache = cpmCache2Dict[instance.MachineCode]; cache.Add(instance.Cpms); if ((DateTime.Now - cache.LastUploadTime).TotalMilliseconds > HmiConfig.UploadWebBoardInterval || cache.DataCount > 100) { await Task.Run(() => { List <StringBuilder> builders = new List <StringBuilder>(cache.DataCount); for (var i = 0; i < cache.DataCount; i++) { builders.Add(InfluxDbHelper.GetInfluxDbService().GetCpms2WriteString(instance.MachineCode, cache.Data[i].Cpms, cache.Data[i].pickTime)); } //清空缓存 cache.LastUploadTime = DateTime.Now; cache.Clear(); bool success = InfluxDbHelper.GetInfluxDbService().WriteMultiString(builders.ToArray()); if (success) { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbSuccess()); } else { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbFailed()); } }); } } catch (Exception e) { Logger.Error("influxDb 上传出错", e); } }