作者 赵彬吉

update

@@ -43,43 +43,50 @@ class RankData extends BaseCommands @@ -43,43 +43,50 @@ class RankData extends BaseCommands
43 */ 43 */
44 public function do() 44 public function do()
45 { 45 {
  46 + try {
  47 +
  48 +
46 Log::channel('rank_data')->info('开始-排名数据'); 49 Log::channel('rank_data')->info('开始-排名数据');
47 //同步api_no 50 //同步api_no
48 try { 51 try {
49 $this->SyncApiNo(); 52 $this->SyncApiNo();
50 - }catch (\Exception $e){ 53 + } catch (\Exception $e) {
51 Log::channel('rank_data')->error('同步api_no失败:' . $e->getMessage()); 54 Log::channel('rank_data')->error('同步api_no失败:' . $e->getMessage());
52 } 55 }
53 56
54 57
55 //所有项目 今日是否达标 重置 58 //所有项目 今日是否达标 重置
56 //有失败会重跑任务,导致达标又被重置 加缓存一天只重置一次 59 //有失败会重跑任务,导致达标又被重置 加缓存一天只重置一次
57 - if(!Cache::get('clear_remain_today_'.date('Y-m-d'))){ 60 + if (!Cache::get('clear_remain_today_' . date('Y-m-d'))) {
58 Project::where('is_remain_today', 1)->update(['is_remain_today' => 0]); 61 Project::where('is_remain_today', 1)->update(['is_remain_today' => 0]);
59 - Cache::set('clear_remain_today_'.date('Y-m-d'), 1, 24 * 3600); 62 + Cache::set('clear_remain_today_' . date('Y-m-d'), 1, 24 * 3600);
60 } 63 }
61 64
62 $error = 0; 65 $error = 0;
63 $api = new QuanqiusouApi(); 66 $api = new QuanqiusouApi();
64 //有排名api编号的项目 67 //有排名api编号的项目
65 - $list = DeployOptimize::where('api_no', '>' , 0)->select('api_no','minor_languages','project_id')->get();  
66 - Log::channel('rank_data')->info('开始-排名数据-'.count($list)); 68 + $list = DeployOptimize::where('api_no', '>', 0)->select('api_no', 'minor_languages', 'project_id')->get();
  69 + Log::channel('rank_data')->info('开始-排名数据-' . count($list));
67 //当日所有站点谷歌收录数据 70 //当日所有站点谷歌收录数据
68 $site_res = $api->getSiteRes(); 71 $site_res = $api->getSiteRes();
69 - if(!$site_res){ 72 + if (!$site_res) {
70 return false; 73 return false;
71 } 74 }
72 - foreach ($list as $item){ 75 + foreach ($list as $item) {
73 echo $item['api_no'] . PHP_EOL; 76 echo $item['api_no'] . PHP_EOL;
74 try { 77 try {
75 (new RankDataLogic())->syncRankData($item['api_no'], $site_res); 78 (new RankDataLogic())->syncRankData($item['api_no'], $site_res);
76 - }catch (\Exception $e){ 79 + } catch (\Exception $e) {
77 Log::channel('rank_data')->error('RankData:失败 ' . $item['api_no'] . $e->getMessage()); 80 Log::channel('rank_data')->error('RankData:失败 ' . $item['api_no'] . $e->getMessage());
78 $error++; 81 $error++;
79 continue; 82 continue;
80 } 83 }
81 } 84 }
82 return !$error; 85 return !$error;
  86 + } catch (\Exception $e) {
  87 + Log::channel('rank_data')->error('排名数据任务失败 ' . $e->getMessage());
  88 + throw new \Exception($e->getMessage());
  89 + }
83 } 90 }
84 91
85 /** 92 /**
@@ -98,7 +105,7 @@ class RankData extends BaseCommands @@ -98,7 +105,7 @@ class RankData extends BaseCommands
98 105
99 $api = new QuanqiusouApi(); 106 $api = new QuanqiusouApi();
100 $ai_nos = $api->getWebApiNo(); 107 $ai_nos = $api->getWebApiNo();
101 - 108 + if($ai_nos){
102 foreach ($deploy_optimizes as $deploy_optimize){ 109 foreach ($deploy_optimizes as $deploy_optimize){
103 $domain = DomainInfo::where('id', $deploy_optimize['domain'])->value('domain'); 110 $domain = DomainInfo::where('id', $deploy_optimize['domain'])->value('domain');
104 if(!$domain){ 111 if(!$domain){
@@ -111,5 +118,6 @@ class RankData extends BaseCommands @@ -111,5 +118,6 @@ class RankData extends BaseCommands
111 } 118 }
112 } 119 }
113 } 120 }
  121 + }
114 122
115 } 123 }