作者 邓超

x

@@ -41,7 +41,7 @@ class HotMail { @@ -41,7 +41,7 @@ class HotMail {
41 private function start(){ 41 private function start(){
42 _echo('启动预热邮件处理 '.getmypid()); 42 _echo('启动预热邮件处理 '.getmypid());
43 43
44 - if(redis()->add('hot_mail_sync',1,60)){ 44 + if(redis()->add('hot_mail_sync',1,30)){
45 $fob = $this->getFobHotEmail(); 45 $fob = $this->getFobHotEmail();
46 46
47 // 把黑格自己的也算进去 47 // 把黑格自己的也算进去
@@ -63,67 +63,11 @@ class HotMail { @@ -63,67 +63,11 @@ class HotMail {
63 }catch (Throwable $e){} 63 }catch (Throwable $e){}
64 } 64 }
65 65
66 - $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");  
67 - $id = 0;  
68 - while (1){  
69 - $ids = [];  
70 - for ($i=0;$i<1000;$i++){  
71 - $ids[] = $i+$id;  
72 } 66 }
73 - $id = end($ids);  
74 67
75 - redis()->rPush('hot_check_ids',implode(',',$ids));  
76 68
77 - if($id>$maxId){  
78 - break; 69 + echo date('d H:i:s').' ==》 已执行完成'.PHP_EOL;
79 } 70 }
80 - }  
81 -  
82 - }  
83 -  
84 -  
85 - while (1){  
86 - $ids = redis()->lPop('hot_check_ids');  
87 - if($ids){  
88 - $ids = explode(',',$ids);  
89 - $this->run($ids);  
90 - }else{  
91 - echo '等待'.PHP_EOL;  
92 - co::sleep(2);  
93 - }  
94 - }  
95 -  
96 -  
97 -  
98 -  
99 - echo '已执行完成'.PHP_EOL;  
100 - }  
101 -  
102 -  
103 - private $folder = [];  
104 -  
105 - private function run($id){  
106 - $list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'is_hots'=>0]),'`id`,`from`,`to`,`folder_id`'));  
107 - foreach ($list as $item){  
108 - if(empty($this->folder[$item['folder_id']])){  
109 - $this->folder[$item['folder_id']] = folderAlias($this->db->value(\Model\folderSql::first($item['folder_id'],'folder')));  
110 - }  
111 -  
112 - // 是否是发件箱  
113 - if($this->folder[$item['folder_id']] == '发件箱'){  
114 - $w = ['email' => explode(',',$item['to'])];  
115 - }else{  
116 - $w = ['email' =>$item['from']];  
117 - }  
118 - // 是否在 预热邮箱中  
119 - if($this->db->cache(300)->count('select count(*) from `hot_mail` where '.dbWhere($w))){  
120 -  
121 - $ret = $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$item['id']]));  
122 - echo date('d H:i:s').' ==》 '.$item['id'].':'.$ret."\n";  
123 - }  
124 - }  
125 - }  
126 -  
127 71
128 /** 72 /**
129 * 获取预热邮箱 73 * 获取预热邮箱
@@ -134,7 +78,7 @@ class HotMail { @@ -134,7 +78,7 @@ class HotMail {
134 */ 78 */
135 private function getHotEmail($t='e'):array { 79 private function getHotEmail($t='e'):array {
136 $url['e'] = 'https://oa.shopk.com/api/mail/preheat'; 80 $url['e'] = 'https://oa.shopk.com/api/mail/preheat';
137 - $url['w'] = 'https://oa.shopk.com/api/mail/write?iswrite=1'; 81 + $url['w'] = 'https://oa.shopk.com/api/mail/write?iswrite=1&id=11321';
138 $data = @file_get_contents($url[$t]); 82 $data = @file_get_contents($url[$t]);
139 83
140 if($data){ 84 if($data){
@@ -174,15 +118,18 @@ swoole_set_process_name('hot-email-run-man'); @@ -174,15 +118,18 @@ swoole_set_process_name('hot-email-run-man');
174 118
175 $pm = new Swoole\Process\Manager(); 119 $pm = new Swoole\Process\Manager();
176 120
177 -$pm->addBatch(10,function (){ 121 +$pm->addBatch(1,function (){
178 122
179 swoole_set_process_name('hot-email-run'); 123 swoole_set_process_name('hot-email-run');
180 124
181 include_once "../vendor/autoload.php"; 125 include_once "../vendor/autoload.php";
182 126
  127 + while(1){
183 new HotMail(); 128 new HotMail();
184 // 执行完了暂停5分钟在执行 129 // 执行完了暂停5分钟在执行
185 - sleep(120); 130 + sleep(40);
  131 + }
  132 +
186 },true); 133 },true);
187 134
188 $pm->start(); 135 $pm->start();
  1 +<?php
  2 +
  3 +use Model\listsSql;
  4 +
  5 +
  6 +/**
  7 + * 处理预热邮箱
  8 + * @author:dc
  9 + * @time 2024/9/4 11:02
  10 + * Class HotMail
  11 + */
  12 +class HotMail {
  13 +
  14 + public function __construct(){
  15 + $this->db = db();
  16 + $this->start();
  17 + }
  18 +
  19 + /**
  20 + * shopk那边的预热邮箱
  21 + * @var array
  22 + */
  23 + private $hotEmail = [];
  24 +
  25 + /**
  26 + * @var \Lib\Db|\Lib\DbPool
  27 + */
  28 + private $db;
  29 +
  30 +
  31 + /**
  32 + * @author:dc
  33 + * @time 2024/7/18 14:04
  34 + */
  35 + private function start(){
  36 + _echo('启动预热邮件处理 '.getmypid());
  37 +
  38 + if(redis()->add('hot_mail_sync',1,60)){
  39 +
  40 + $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
  41 + $id = 0;
  42 + while (1){
  43 + $ids = [];
  44 + for ($i=0;$i<1000;$i++){
  45 + $ids[] = $i+$id;
  46 + }
  47 + $id = end($ids);
  48 +
  49 + redis()->rPush('hot_check_ids',implode(',',$ids));
  50 +
  51 + if($id>$maxId){
  52 + break;
  53 + }
  54 + }
  55 +
  56 + }
  57 +
  58 +
  59 + while (1){
  60 + $ids = redis()->lPop('hot_check_ids');
  61 + if($ids){
  62 + $ids = explode(',',$ids);
  63 + $this->run($ids);
  64 + }else{
  65 + echo '等待'.PHP_EOL;
  66 + co::sleep(2);
  67 + }
  68 + }
  69 +
  70 + }
  71 +
  72 +
  73 + private $folder = [];
  74 +
  75 + private function run($id){
  76 + $list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'is_hots'=>0]),'`id`,`from`,`to`,`folder_id`'));
  77 + foreach ($list as $item){
  78 + if(empty($this->folder[$item['folder_id']])){
  79 + $this->folder[$item['folder_id']] = folderAlias($this->db->value(\Model\folderSql::first($item['folder_id'],'folder')));
  80 + }
  81 +
  82 + // 是否是发件箱
  83 + if($this->folder[$item['folder_id']] == '发件箱'){
  84 + $w = ['email' => explode(',',$item['to'])];
  85 + }else{
  86 + $w = ['email' =>$item['from']];
  87 + }
  88 + // 是否在 预热邮箱中
  89 + if($this->db->cache(300)->count('select count(*) from `hot_mail` where '.dbWhere($w))){
  90 +
  91 + $ret = $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$item['id']]));
  92 + echo date('d H:i:s').' ==》 '.$item['id'].':'.$ret."\n";
  93 + }
  94 + }
  95 + }
  96 +
  97 +
  98 +}
  99 +
  100 +
  101 +swoole_set_process_name('hot-email-run-man');
  102 +
  103 +$pm = new Swoole\Process\Manager();
  104 +
  105 +$pm->addBatch(10,function (){
  106 +
  107 + swoole_set_process_name('hot-email-run');
  108 +
  109 + include_once "../vendor/autoload.php";
  110 +
  111 + new HotMail();
  112 +
  113 + exit();
  114 +},true);
  115 +
  116 +$pm->start();
  117 +
  118 +