作者 邓超

优化同步

@@ -61,7 +61,6 @@ class SyncToEsCmd { @@ -61,7 +61,6 @@ class SyncToEsCmd {
61 61
62 $code = $es->save($doc_id,$data); 62 $code = $es->save($doc_id,$data);
63 if($code!==200){ 63 if($code!==200){
64 - _echo('同步es: '.$doc_id.'===>'.$code);  
65 sleep(1); 64 sleep(1);
66 $code = $es->save($doc_id,$data); // 重试一次 65 $code = $es->save($doc_id,$data); // 重试一次
67 } 66 }
@@ -18,7 +18,8 @@ class Es { @@ -18,7 +18,8 @@ class Es {
18 // private $host = 'https://es-az664rii.public.tencentelasticsearch.com:9200'; // aicc 服务器 18 // private $host = 'https://es-az664rii.public.tencentelasticsearch.com:9200'; // aicc 服务器
19 private $host = [ 19 private $host = [
20 // 'http://elastic:1qOtfZhqy4B7IXdIpl_W@192.168.80.129:9200', 20 // 'http://elastic:1qOtfZhqy4B7IXdIpl_W@192.168.80.129:9200',
21 - 'http://elastic:L6PY7r4FsHmEBYFK@127.0.0.1:9200' 21 + 'http://elastic:L6PY7r4FsHmEBYFK@127.0.0.1:9200',
  22 +// 'https://ai-email:3mLbEKwDX9YjUDFm@172.19.0.56:9200'
22 ]; //内网地址 公网要加ip白名单 23 ]; //内网地址 公网要加ip白名单
23 24
24 25
@@ -36,9 +37,11 @@ class Es { @@ -36,9 +37,11 @@ class Es {
36 * Es constructor. 37 * Es constructor.
37 * @param $index 38 * @param $index
38 */ 39 */
39 - public function __construct($index) 40 + public function __construct($index,array $host=[])
40 { 41 {
41 - 42 + if($host){
  43 + $this->host = $host;
  44 + }
42 $this->index = $index; 45 $this->index = $index;
43 46
44 $this->client = ClientBuilder::create() 47 $this->client = ClientBuilder::create()
@@ -80,7 +83,7 @@ class Es { @@ -80,7 +83,7 @@ class Es {
80 try { 83 try {
81 $response = $this->client->search($params); 84 $response = $this->client->search($params);
82 }catch (\Throwable $e) { 85 }catch (\Throwable $e) {
83 - logs("搜索数据es:".$e->getMessage()); 86 + logs("搜索数据es:".$e->getMessage()." \n ".json_encode($params));
84 return []; 87 return [];
85 } 88 }
86 89
@@ -104,7 +107,7 @@ class Es { @@ -104,7 +107,7 @@ class Es {
104 try { 107 try {
105 $response = $this->client->count($params); 108 $response = $this->client->count($params);
106 }catch (\Throwable $e) { 109 }catch (\Throwable $e) {
107 - logs("搜索数据es:".$e->getMessage()); 110 + logs("搜索数据es:".$e->getMessage()." \n ".json_encode($params));
108 return 0; 111 return 0;
109 } 112 }
110 113
@@ -129,7 +132,7 @@ class Es { @@ -129,7 +132,7 @@ class Es {
129 try { 132 try {
130 $response = $this->client->get($params); 133 $response = $this->client->get($params);
131 }catch (\Throwable $e) { 134 }catch (\Throwable $e) {
132 - logs("读取数据es:".$e->getMessage()); 135 + logs("读取数据es:".$e->getMessage()." \n ".json_encode($params));
133 return []; 136 return [];
134 } 137 }
135 138
@@ -360,7 +360,7 @@ class SyncMail { @@ -360,7 +360,7 @@ class SyncMail {
360 return 0; 360 return 0;
361 } 361 }
362 if($maxUid){ 362 if($maxUid){
363 - $lists = $msg->uid(1)->get($maxUid.':*')->all(); 363 + $lists = $msg->uid(1)->get(($maxUid+1).':*')->all();
364 if($lists){ 364 if($lists){
365 $this->saveMail($folder_id,$lists,$isBody); 365 $this->saveMail($folder_id,$lists,$isBody);
366 return count($lists); 366 return count($lists);