public void Execute(IJobExecutionContext context) { try { var sw = new Stopwatch(); sw.Start(); var userDatas = ProductCacheDal.GetProductRecommendByUserId(); var defaultDatas = ProductCacheDal.GetCommonRecommend(); var needRefreshPids = userDatas.Union(defaultDatas).Distinct().ToList(); var referData = DateTime.Now.Subtract(TimeSpan.FromHours(1)); if (!needRefreshPids.Any()) { Logger.Info("bi推荐产品刷新到esjob执行,并没有找到需要更新的数据"); } else { Logger.Info($"bi推荐产品刷新到esjob开始执行,一共{needRefreshPids.Count}个产品"); using (var client = new CacheClient()) { foreach (var pids in needRefreshPids.Split(1).Select(r => r.ToList())) { var switcher = ProductCacheDal.SelectRuntimeSwitchBySwitchName(); if (switcher == "run") { var esresult = client.RefreshProductRecommendEsCacheByPids(pids); if (!esresult.Success || !esresult.Result) { Logger.Error($"调用bi推荐产品刷新到es接口失败", esresult.Exception.InnerException); } } else { return; } } } using (var client = new ProductSearchClient()) { var delResult = client.DeleteOldProductEs(referData, ExpiredEsDataType.Recommend); if (!delResult.Success || !delResult.Result) { Logger.Error($"调用bi推荐产品删除es过期数据接口失败", delResult.Exception.InnerException); } } } sw.Stop(); Logger.Info($"bi推荐产品刷新到esjob执行结束,耗时{sw.ElapsedMilliseconds}"); } catch (Exception ex) { Logger.Error("bi推荐产品刷新到es失败", ex); } }
public void Execute(IJobExecutionContext context) { Logger.Info($"开始刷新Suggest"); var client = new ProductSearchClient(); var suggestList = ProductCacheDal.SelectSuggestWord(brash); foreach (var oneList in suggestList) { var response = client.SearchKeywordsResultNumber(oneList.Select(_ => _.Keyword).Distinct().ToList()); if (!response.Success) { client = new ProductSearchClient(); response = client.SearchKeywordsResultNumber(oneList.Select(_ => _.Keyword).ToList()); if (response.Success) { if (!response.Success) { Logger.Error($"服务调用失败"); return; } } } if (response.Result == null) { Logger.Warn($"服务返回null;{response.ErrorMessage}"); continue; } var upUnActive = ProductCacheDal.UpdateSuggestActive( response.Result.Where(_ => _.Value == 0).Select(_ => _.Key).ToList() , false); var upActive = ProductCacheDal.UpdateSuggestActive( response.Result.Where(_ => _.Value > 0).Select(_ => _.Key).ToList() , true); if (!upUnActive) { Logger.Warn($"数据库更新失败upUnActive;"); continue; } if (!upActive) { Logger.Warn($"数据库更新失败upActive;"); continue; } } Logger.Info($"刷新Suggest完成;通知刷新 RebuildSuggest"); TuhuNotification.SendNotification("ProductModify", new { type = "RebuildSuggest" }); }
public void Execute(IJobExecutionContext context) { Logger.Info($"开始刷新数据"); var nodeNoList = ProductCacheDal.SelectAllProductNode(); var categoryList = ProductCacheDal.SelectAllCategoryNodeNo().ToList(); var max = nodeNoList.Sum(p => p.NodeNo.Split('.').Count()); var allnodeNoList = new List <ProductNodeModel>(max); nodeNoList.ForEach(p => { var nodeNos = p.NodeNo.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < nodeNos.Count(); i++) { var node = string.Join(".", nodeNos.Take(i + 1)); allnodeNoList.Add(new ProductNodeModel() { NodeNo = node, ProductCount = p.ProductCount }); } }); var result = allnodeNoList.GroupBy(p => p.NodeNo) .ToDictionary(p => p.Key, s => s.Sum(ss => ss.ProductCount)); categoryList.ForEach(p => { if (result.ContainsKey(p.NodeNo)) { p.ProductCount = result[p.NodeNo]; } }); Logger.Info($"开始更新数据;总量:{categoryList.Count}"); var branchN = 0; foreach (var one in categoryList) { branchN++; var upResult = ProductCacheDal.UpdateProductNodeCNT(one.NodeNo, one.ProductCount); if (!upResult) { Logger.Warn($"刷新失败;{one.NodeNo}:{one.ProductCount}"); } if (branchN % brash == 0) { Thread.Sleep(1000); } } Logger.Info($"刷新完成"); }
public void Execute(IJobExecutionContext context) { Logger.Info($"开始刷新"); int count = 0; var result = ProductCacheDal.SelectCommonProductEsPids(500); if (result != null) { Parallel.ForEach(result, new ParallelOptions() { MaxDegreeOfParallelism = 4, TaskScheduler = TaskScheduler.Default }, parseitem => { count++; Logger.Info($"开始刷新{count}批次"); if (parseitem != null && parseitem.Any()) { var setitems = (from item in parseitem.AsParallel() group item by item.Value into g select new { items = g.Select(x => x.Key)?.ToList(), type = g.Key })?.ToList(); foreach (var setitem in setitems) { try { using (var client = new Tuhu.Service.Product.ShopProductClient()) { var setresult = client.SetEsCacheByPids(setitem.items, setitem.type); setresult.ThrowIfException(true); } } catch (System.Exception ex) { Logger.Warn(ex); } } } Logger.Info($"结束刷新{count}批次"); }); } Logger.Info($"结束刷新"); }
public void Execute(IJobExecutionContext context) { using (var cacheClient = new CacheClient()) { //刷新轮胎适配redis缓存 var refreshTireAsync = cacheClient.RefreshTireAdpterCache(null, 1); if (!refreshTireAsync.Success) { Logger?.Warn($"RefreshTireAdpterCache刷新失败:{refreshTireAsync.ErrorMessage}", refreshTireAsync.Exception); } } //获取所有tid var allTids = ProductCacheDal.SelectAllTids(); using (var cacheClient = new CacheClient()) { //清除缓存 var baoyangAdapterTire = cacheClient.RefreshBaoYangVehicleAdpterCache(new List <int>() { }, true); //分批次刷新保养适配redis缓存 allTids.Split(100).ForEach(p => { var resultOne = cacheClient.RefreshBaoYangVehicleAdpterCache(p.ToList(), false); if (!resultOne.Success) { using (var cacheClient2 = new CacheClient()) { resultOne = cacheClient2.RefreshBaoYangVehicleAdpterCache(p.ToList(), false); if (!resultOne.Success) { Logger?.Warn($"RefreshBaoYangVehicleAdpterCache刷新失败", resultOne.Exception); } } } }); } //发送刷新通知 Logger.Info($"notification.productmatch.modify.RebuildAdpter=>{DateTime.Now}"); TuhuNotification.SendNotification("notification.productmatch.modify", new { type = "RebuildAdpter" }); //TuhuNotification.SendNotification("notification.productmatch.modify", new { type = "UpdateAdpter", pids=new string[] { } }); }
public void Execute(IJobExecutionContext context) { try { var sw = new Stopwatch(); sw.Start(); var needRefreshPids = ProductCacheDal.GetProductRecommendByPid()?.ToList(); var referData = DateTime.Now.Subtract(TimeSpan.FromHours(1)); if (needRefreshPids == null || !needRefreshPids.Any()) { Logger.Info("bi按照产品推荐产品刷新到Redisjob执行,并没有找到需要更新的数据"); } else { Logger.Info($"bi按照产品推荐产品刷新到Redisjob开始执行,一共{needRefreshPids.Count}个产品"); using (var client = new CacheClient()) { foreach (var pids in needRefreshPids.Split(100).Select(r => r.ToList())) { var esresult = client.RefreshProductRecommendByPids(pids); if (!esresult.Success || !esresult.Result) { Logger.Error($"调用bi按照产品推荐产品刷新到Redis失败", esresult.Exception.InnerException); } else { return; } } } } sw.Stop(); Logger.Info($"bi推荐产品刷新到redisjob执行结束,耗时{sw.ElapsedMilliseconds}"); } catch (Exception ex) { Logger.Error("bi推荐产品刷新到redis失败", ex); } }
public void Execute(IJobExecutionContext context) { mgIndex++; Logger.Info($"启动任务=>{mgIndex}"); var dt = DateTime.Now; var isDeleteOld = true; var cnt = ProductCacheDal.GetProductEsCount(); Logger?.Info($"RGZ{mgIndex}=更新产品总数为:" + cnt); if (cnt == 0) { return; } var batchCnt = 500; var pageCnt = Math.Ceiling((double)cnt / batchCnt); for (var i = 1; i <= pageCnt; i++) { var pids = ProductCacheDal.GetProductEsPids(batchCnt, i); using (var client = new ProductSearchClient()) { var result = client.RebuildProductEs(pids); if (!result.Success) { using (var client2 = new ProductSearchClient()) { Thread.Sleep(200); result = client2.RebuildProductEs(pids); if (!result.Success) { Logger?.Warn($"RGZ{mgIndex}={i}=失败,不删除老数据:{result.ErrorCode};{result.ErrorMessage}"); isDeleteOld = false; continue; } } } } Logger?.Info($"RGZ{mgIndex}={i}=成功"); } if (!isDeleteOld) { Logger?.Info($"RGZ{mgIndex}=有更新错误的数据,不删除老数据"); return; } //防止更新延迟误删 Thread.Sleep(TimeSpan.FromMinutes(1)); using (var client3 = new ProductSearchClient()) { var deleteResult = client3.DeleteOldProductEs(dt); if (!deleteResult.Success) { Logger?.Info($"RGZ{mgIndex}=删除老数据出错"); } } Logger?.Info($"RGZ{mgIndex}全部成功"); return; }
public void Execute(IJobExecutionContext context) { try { const int pageSize = 800; decimal num = ProductCacheDal.SelectSkuProductCount(); var pageNum = Convert.ToInt32(Math.Ceiling(num / pageSize)); bool issuccess = true; string key = ""; Logger.Info($"{JobBatch}=>刷新缓存服务开始.一共{num}个产品.一共{pageNum}批次."); Stopwatch watch = new Stopwatch(); watch.Start(); if (DateTime.Now.Hour >= 2 && DateTime.Now.Hour <= 4) { using (var cacheclient = new CacheClient()) { var keyresult = cacheclient.GenerateProdutCacheKeyPrefix(); keyresult.ThrowIfException(true); key = keyresult.Result; } } var client = new CacheClient(); for (var i = 1; i <= pageNum + 1; i++) { Thread.Sleep(5); var result = client.RefreshProductCacheByPageNumAndKeyPrefix(i, pageSize, JobBatch, key); Logger.Info($"{JobBatch}=>{i}批次刷新{(result.Result ? "成功" : "失败")}.用时{result.ElapsedMilliseconds}"); if (!result.Success || !result.Result) //失败重新创建client { Thread.Sleep(1000); client = new CacheClient(); var result2 = client.RefreshProductCacheByPageNumAndKeyPrefix(i, pageSize, JobBatch, key); Logger.Info($"{JobBatch}=>{i}批次重试刷新{(result2.Result ? "成功" : "失败")}.用时{result2.ElapsedMilliseconds}"); if (!result2.Success) //失败重新创建client { client = new CacheClient(); } } issuccess = issuccess && result.Result; } using (var cacheclient = new CacheClient()) { var setresult = cacheclient.SetProdutCacheKeyPrefix(key); if (!setresult.Success && setresult.ErrorCode != "keyPrefix") { Logger.Warn($"刷新产品缓存,换key失败。{setresult.ErrorMessage}", setresult.Exception); } Logger.Info($"{JobBatch}=>刷新产品缓存.换key.{setresult.Result};key=>{key}"); } watch.Stop(); if (issuccess) { Logger.Info($"{JobBatch}=>刷新成功用时{watch.ElapsedMilliseconds}"); } else { Logger.Error($"{JobBatch}=>刷新失败用时{watch.ElapsedMilliseconds}"); } } catch (Exception e) { Logger.Error($"{JobBatch}=>刷新产品缓存异常", e); } JobBatch++; }
public void Execute(IJobExecutionContext context) { var curDateTime = DateTime.Now; Logger.Info($"发送产品标签更新通知:{curDateTime}"); TuhuNotification.SendNotification("notification.productModify.ProductCommonTag", new { type = "RefreshInterval", timespan = curDateTime }); if (curDateTime.Hour == 8 && curDateTime.Minute == 20) //8点20分 { Logger.Info($"notification.productmatch.modify.RebuildActivity=>{curDateTime}"); TuhuNotification.SendNotification("notification.productmatch.modify", new { type = "RebuildActivity" }); } if (curDateTime.Hour == 16 && curDateTime.Minute == 30) //16点30分 { Logger.Info($"notification.productmatch.modify.RebuildActivity=>{curDateTime}"); TuhuNotification.SendNotification("notification.productmatch.modify", new { type = "RebuildActivity" }); } if (curDateTime.Hour >= 4 && curDateTime.Hour <= 23 && curDateTime.Minute == 13) //4点到23点 每隔1小时触发一次 { Logger.Info($"notification.productmatch.modify.RebuildPerHourEsCache=>{curDateTime}"); TuhuNotification.SendNotification("notification.productmatch.modify", new { type = "RebuildPerHourEsCache" }); } if (curDateTime.Hour == 2 && curDateTime.Minute == 16) //2点16分 { Logger.Info($"ProductNodeCntRefreshJob刷新类目下的产品数量=>{curDateTime}"); new ProductNodeCntRefreshJob().Execute(null); } if (curDateTime.Hour == 7 && curDateTime.Minute == 16) //7点16分 { Logger.Info($"notification.ProductModify.ProductCacheModify.ProductLimit=>{curDateTime}"); TuhuNotification.SendNotification("notification.ProductModify.ProductCacheModify", new { type = "ProductLimit" }); } if (curDateTime.Minute % 10 == 0) //每十分钟刷新一次 { #region 刷新所有缓存 Logger.Info($"开始刷新所有活动缓存"); var sw = new Stopwatch(); sw.Start(); try { using (var client = new CacheClient()) { var result = client.RefreshProductSaleActivityCache(); if (!result.Success) { Logger.Error("刷新所有活动失败RefreshProductSaleActivityCache"); } } sw.Stop(); } catch (Exception e) { Logger.Error("调用刷新所有活动失败RefreshProductSaleActivityCache" + e.InnerException + e.Message); } Logger.Info($"刷新所有活动缓存耗时{sw.ElapsedMilliseconds}"); #endregion #region pid刷新缓存 sw.Restart(); Logger.Info($"开始按pid刷新所有活动缓存"); try { var datas = ProductCacheDal.SelectAllSaleActivity(); var pids = datas.Select(r => r.PID).ToList(); using (var client = new CacheClient()) { var result = client.RefreshProductSaleActivityCacheByPids(pids); if (!result.Success) { Logger.Error("按pid刷新所有活动失败RefreshProductSaleActivityCache"); } } sw.Stop(); } catch (Exception e) { Logger.Error("调用按pid刷新所有活动失败RefreshProductSaleActivityCache" + e.InnerException + e.Message); } Logger.Info($"按pid刷新所有活动缓存耗时{sw.ElapsedMilliseconds}"); #endregion } }