...
|
...
|
@@ -4,6 +4,13 @@ |
|
|
|
|
|
require_once "../vendor/autoload.php";
|
|
|
|
|
|
|
|
|
if(in_array('v2',$argv)){
|
|
|
define('S_V2','2');
|
|
|
}else{
|
|
|
define('S_V2','');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 把mysql的数据同步到es
|
|
|
* @author:dc
|
...
|
...
|
@@ -37,7 +44,12 @@ class SyncToEsCmd { |
|
|
// pcntl_signal(SIGHUP, $handler);
|
|
|
|
|
|
|
|
|
if(S_V2){
|
|
|
$es = es('email_lists');
|
|
|
}else{
|
|
|
$es = es();
|
|
|
}
|
|
|
|
|
|
$db = db();
|
|
|
$this->fob_db = fob_mysql();
|
|
|
$startTime = time();
|
...
|
...
|
@@ -55,14 +67,14 @@ class SyncToEsCmd { |
|
|
break;
|
|
|
}
|
|
|
|
|
|
$id = redis()->lPop('sync_to_es');
|
|
|
$id = redis()->lPop('sync_to_es'.S_V2);
|
|
|
$code = 500;
|
|
|
if($id){
|
|
|
$doc_id = '';
|
|
|
try {
|
|
|
$data = $db->throw()->first(\Model\listsSql::first('`id` = '.$id));
|
|
|
}catch (Throwable $e){
|
|
|
redis()->rPush('sync_to_es',$id);
|
|
|
redis()->rPush('sync_to_es'.S_V2,$id);
|
|
|
_echo('sync to es '.$e->getMessage());
|
|
|
break;
|
|
|
}
|
...
|
...
|
@@ -70,6 +82,7 @@ class SyncToEsCmd { |
|
|
if($data){
|
|
|
// 设置 进程 是否在运行
|
|
|
$data['is_auto']=$db->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0;
|
|
|
try {
|
|
|
// 文件夹
|
|
|
if(empty($this->folders[$data['folder_id']])){
|
|
|
$this->folders[$data['folder_id']] = $db->throw()->value(\Model\folderSql::first($data['folder_id'],'folder'));
|
...
|
...
|
@@ -78,7 +91,11 @@ class SyncToEsCmd { |
|
|
$data['folder_as_int'] = folder2int($this->folders[$data['folder_id']]);
|
|
|
// postid ai邮箱要用 这个是查询黑格
|
|
|
$data['postid'] = $this->getPostid($data['email_id']);
|
|
|
|
|
|
}catch (Throwable $e){
|
|
|
redis()->rPush('sync_to_es'.S_V2,$id);
|
|
|
_echo('sync to es '.$e->getMessage());
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
$data = $this->getEsData($data);
|
|
|
$doc_id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid'];
|
...
|
...
|
@@ -87,7 +104,7 @@ class SyncToEsCmd { |
|
|
}
|
|
|
|
|
|
if($code!==200){
|
|
|
@file_put_contents(LOG_PATH.'/sync_es_fail.log',$id."\n",FILE_APPEND);
|
|
|
@file_put_contents(LOG_PATH.'/sync_es_fail'.S_V2.'.log',$id."\n",FILE_APPEND);
|
|
|
_echo('同步es: '.$doc_id.'===>'.$code);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -106,9 +123,14 @@ class SyncToEsCmd { |
|
|
* @time 2025/5/20 15:44
|
|
|
*/
|
|
|
public function getPostid($email_id){
|
|
|
$h = date('dhi');
|
|
|
if(empty($this->postids[$h][$email_id])){
|
|
|
$id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' and `source` = 2 and `deleted_at` is null order by `id` desc limit 1 ");
|
|
|
$h = date('dh');
|
|
|
if(!isset($this->postids[$h][$email_id])){
|
|
|
// 未删除状态
|
|
|
$id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' and `deleted_at` is null order by `id` desc limit 1 ");
|
|
|
if(!$id){
|
|
|
// 已删状态
|
|
|
$id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' order by `id` desc limit 1 ");
|
|
|
}
|
|
|
$this->postids[$h][$email_id] = $id;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -144,6 +166,8 @@ class SyncToEsCmd { |
|
|
$data['to_name'] = '';
|
|
|
}
|
|
|
}
|
|
|
$data['description'] = str_replace(["\n"],"",$data['description']);
|
|
|
// unset($data['to_name']);
|
|
|
|
|
|
if(!empty($data['created_at'])){
|
|
|
$data['created_at'] = date('Y-m-d\TH:i:s',strtotime($data['created_at']));
|
...
|
...
|
|