private bool DeleteEsData(IEnumerable <UserMessageBoxInfoRelation> relations) { if (relations != null && relations.Any()) { var operations = new List <IBulkOperation>(); var exlogs = ConvertMessageLogToEsLog(relations); foreach (var log in exlogs) { operations.Add(new BulkDeleteOperation <UserMessageBoxInfoRelationC>(log.Id) { Routing = log.UserId }); } var bulkRequest = new BulkRequest(UserMessageBoxRelationIndex) { Operations = operations.ToArray() }; var client = ElasticsearchHelper.CreateClient(); #if DEBUG ElasticsearchHelper.EnableDebug(); #endif var responseOne = client.Bulk(bulkRequest); var errorcount = responseOne.ItemsWithErrors.Count(); DalMessageBox.WriteSyncLogs(relations); return(errorcount <= 0); } return(false); }
public void Execute(IJobExecutionContext context) { Logger.Info($"刷新开始执行"); int count = 0; int maxpkid = 0; int exceptioncount = 0; string runtimename = "HandleExpiredMessageBox"; var result = CheckIsOpenWithDescription(runtimename); if (!result.Item1) { Logger.Info("开关已关,return"); return; } int.TryParse(result.Item2, out maxpkid); #if DEBUG maxpkid = 0; #endif Logger.Info($"maxpkid:{maxpkid}"); var starttime = DateTime.Now; while (true && count <= 554948) { count++; try { result = CheckIsOpenWithDescription(runtimename); if (!result.Item1) { Logger.Info("开关已关,return"); return; } Logger.Info($"第{count}批次循环刷新开始执行,maxpkid:{maxpkid}"); var relations = SelectMessageRelation(maxpkid, starttime); if (relations != null && relations.Any()) { maxpkid = relations.Max(x => x.PKID); var operations = new List <IBulkOperation>(); var exlogs = ConvertMessageLogToEsLog(relations); foreach (var log in exlogs) { operations.Add(new BulkDeleteOperation <UserMessageBoxInfoRelationC>(log.Id) { Routing = log.UserId }); } var bulkRequest = new BulkRequest(DeleteExpiredMessageBoxJob.UserMessageBoxRelationIndex) { Operations = operations.ToArray() }; var client = ElasticsearchHelper.CreateClient(); #if DEBUG ElasticsearchHelper.EnableDebug(); #endif var responseOne = client.Bulk(bulkRequest); var errorcount = responseOne.ItemsWithErrors.Count(); WriteSyncLogs(relations); UpdateRunTimeSwitchDescription(runtimename, maxpkid.ToString()); Logger.Info($"第{count}批次结束刷新.errorcount:{errorcount}"); } else { break; } } catch (System.Exception ex) { maxpkid -= 1000; Logger.Warn(ex); exceptioncount++; if (exceptioncount >= 10) { break; } } } Logger.Info($"刷新结束"); }