作者 邓超

优化同步

@@ -27,10 +27,9 @@ class SyncToEsCmd { @@ -27,10 +27,9 @@ class SyncToEsCmd {
27 // pcntl_signal(SIGHUP, $handler); 27 // pcntl_signal(SIGHUP, $handler);
28 28
29 29
30 - $es = (new Lib\Es\Es('hg_ai_emails')); 30 + $es = es();
31 $db = db(); 31 $db = db();
32 32
33 -  
34 while (1){ 33 while (1){
35 34
36 // 检查是否接收到信号 35 // 检查是否接收到信号
@@ -42,25 +41,25 @@ class SyncToEsCmd { @@ -42,25 +41,25 @@ class SyncToEsCmd {
42 } 41 }
43 42
44 $id = redis()->lPop('sync_to_es'); 43 $id = redis()->lPop('sync_to_es');
  44 + $code = 500;
45 if($id){ 45 if($id){
46 - $data = $db->throw()->first(\Model\listsSql::first('`id` = '.$id)); 46 + $data = $db->first(\Model\listsSql::first('`id` = '.$id));
47 if($data){ 47 if($data){
48 // 设置 进程 是否在运行 48 // 设置 进程 是否在运行
49 - $data['is_auto']=$db->throw()->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0; 49 + $data['is_auto']=$db->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0;
50 50
51 $data = $this->getEsData($data); 51 $data = $this->getEsData($data);
52 $doc_id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid']; 52 $doc_id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid'];
53 53
54 $code = $es->save($doc_id,$data); 54 $code = $es->save($doc_id,$data);
55 - if($code!==200){  
56 - @file_put_contents(LOG_PATH.'/sync_es_fail.log',$id."\n",FILE_APPEND);  
57 - redis()->rPush('sync_to_es',$id);  
58 - _echo('同步es: '.$doc_id.'===>'.$code);  
59 - }  
60 - continue;  
61 } 55 }
62 } 56 }
63 57
  58 + if($code!==200){
  59 + @file_put_contents(LOG_PATH.'/sync_es_fail.log',$id."\n",FILE_APPEND);
  60 + _echo('同步es: '.$doc_id.'===>'.$code);
  61 + }
  62 +
64 sleep(1); 63 sleep(1);
65 } 64 }
66 65
@@ -28,7 +28,7 @@ class MailListV2Es extends Base { @@ -28,7 +28,7 @@ class MailListV2Es extends Base {
28 28
29 public function __construct() 29 public function __construct()
30 { 30 {
31 - $this->es = new Es('hg_ai_emails'); 31 + $this->es = \es();
32 } 32 }
33 33
34 /** 34 /**
@@ -628,4 +628,14 @@ function minMaxToArray($min, $max,$len=1000) { @@ -628,4 +628,14 @@ function minMaxToArray($min, $max,$len=1000) {
628 } 628 }
629 629
630 return $result; 630 return $result;
  631 +}
  632 +
  633 +/**
  634 + * es
  635 + * @return \Lib\Es\Es
  636 + * @author:dc
  637 + * @time 2025/3/8 23:13
  638 + */
  639 +function es(){
  640 + return (new Lib\Es\Es('email_ai_emails',['https://ai-email:3mLbEKwDX9YjUDFm@172.19.0.56:9200']));
631 } 641 }
@@ -18,7 +18,7 @@ class Es { @@ -18,7 +18,7 @@ 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 +// 'https://ai-email:3mLbEKwDX9YjUDFm@172.19.0.56:9200'
22 // 'https://ai-email:3mLbEKwDX9YjUDFm@172.19.0.56:9200' 22 // 'https://ai-email:3mLbEKwDX9YjUDFm@172.19.0.56:9200'
23 ]; //内网地址 公网要加ip白名单 23 ]; //内网地址 公网要加ip白名单
24 24