作者 邓超

重新同步

@@ -29,27 +29,33 @@ class AutoMail { @@ -29,27 +29,33 @@ class AutoMail {
29 echo date('Y-m-d H:i:s'); 29 echo date('Y-m-d H:i:s');
30 echo "\n"; 30 echo "\n";
31 $at = 0; 31 $at = 0;
32 - if(redis()->get('resync_to_es_inbox') == 1){  
33 -  
34 - redis()->set('resync_to_es_inbox',2,3600);  
35 -  
36 - $post_ids = fob_mysql()->all("select `post_id` from `e_mail_binds` group by `post_id`");  
37 -  
38 - if($post_ids){  
39 - $post_ids = array_column($post_ids,'post_id','post_id'); 32 + $this->es = es();
  33 + while (true){
  34 + $postid = redis()->lPop('resync_to_es_inbox_list');
  35 + if (!is_numeric($postid)){
  36 + break;
40 } 37 }
  38 + if(redis()->add('resync_to_es_inbox:'.$postid,1,$postid?600:7200)){
  39 + if (!$postid){
  40 + $post_ids = fob_mysql()->all("select `post_id` from `e_mail_binds` group by `post_id`");
  41 + if($post_ids){
  42 + $post_ids = array_column($post_ids,'post_id','post_id');
  43 + }
  44 + }else{
  45 + $post_ids = [$postid];
  46 + }
  47 +
  48 + foreach ($post_ids as $post_id){
  49 + $total = $this->essss(0,$post_id,0);
  50 + $autoTotal = $this->essss(0,$post_id,1);
  51 + echo "postid {$post_id} inbox {$total} auto {$autoTotal}\n";
  52 + $at += $total + $autoTotal;
  53 + }
41 54
42 - $this->es = es();  
43 -  
44 - foreach ($post_ids as $post_id){  
45 - $total = $this->essss(0,$post_id,0);  
46 - $autoTotal = $this->essss(0,$post_id,1);  
47 - echo "postid {$post_id} inbox {$total} auto {$autoTotal}\n";  
48 - $at += $total + $autoTotal;  
49 } 55 }
50 56
51 - redis()->set('resync_to_es_inbox',2,600);  
52 } 57 }
  58 +
53 echo "总数量 {$at} "; 59 echo "总数量 {$at} ";
54 echo "end "; 60 echo "end ";
55 echo date('Y-m-d H:i:s'); 61 echo date('Y-m-d H:i:s');
@@ -1137,11 +1137,19 @@ class Home extends Base { @@ -1137,11 +1137,19 @@ class Home extends Base {
1137 * @time 2025/9/18 16:50 1137 * @time 2025/9/18 16:50
1138 */ 1138 */
1139 public function resync_to_es(){ 1139 public function resync_to_es(){
1140 - if(redis()->add('resync_to_es_inbox',1,600)){  
1141 - app()->e('请求成功,请等待5-15分钟');  
1142 - }else{ 1140 + $postid = (int) app()->request('postid');
  1141 + if(redis()->has('resync_to_es_inbox:'.$postid)){
1143 app()->e('失败,请等待10分钟后在重试'); 1142 app()->e('失败,请等待10分钟后在重试');
1144 } 1143 }
  1144 + $h = (int) date('H');
  1145 + if(!$postid && $h>=6&& $h<=18){
  1146 + app()->e('刷所有项目只能在早6点前或晚18点后');
  1147 + }
  1148 +
  1149 + redis()->rPush('resync_to_es_inbox_list',$postid);
  1150 +
  1151 + app()->e('请求成功,请等待5-15分钟');
  1152 +
1145 } 1153 }
1146 1154
1147 1155