作者 邓超

x

@@ -41,43 +41,61 @@ class HotMail { @@ -41,43 +41,61 @@ class HotMail {
41 private function start(){ 41 private function start(){
42 _echo('启动预热邮件处理 '.getmypid()); 42 _echo('启动预热邮件处理 '.getmypid());
43 43
44 - $fob = $this->getFobHotEmail(); 44 + if(redis()->add('hot_mail_sync',1)){
  45 + $fob = $this->getFobHotEmail();
45 46
46 - // 把黑格自己的也算进去  
47 - $this->shopkHotEmail = array_merge($this->getHotEmail('e'),$this->getHotEmail('w'),$fob); 47 + // 把黑格自己的也算进去
  48 + $this->shopkHotEmail = array_merge($this->getHotEmail('e'),$this->getHotEmail('w'),$fob);
48 49
49 - $this->shopkHotEmail = array_map('strtolower',$this->shopkHotEmail); 50 + $this->shopkHotEmail = array_map('strtolower',$this->shopkHotEmail);
50 51
51 - $this->shopkHotEmail = array_flip($this->shopkHotEmail); 52 + $this->shopkHotEmail = array_flip($this->shopkHotEmail);
52 53
53 - $this->shopkHotEmail['job@aicc-email.com'] = 1; 54 + $this->shopkHotEmail['job@aicc-email.com'] = 1;
54 55
55 - foreach ($this->shopkHotEmail as $e=>$i){  
56 - try {  
57 - if(!$this->db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$e]))){  
58 - $this->db->throw()->insert('hot_mail',['email'=>$e],false); 56 + foreach ($this->shopkHotEmail as $e=>$i){
  57 + try {
  58 + if(!$this->db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$e]))){
  59 + $this->db->throw()->insert('hot_mail',['email'=>$e],false);
  60 + }
  61 +
  62 + }catch (Throwable $e){}
  63 + }
  64 +
  65 + $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
  66 + $id = 0;
  67 + while (1){
  68 + $ids = [];
  69 + for ($i=0;$i<1000;$i++){
  70 + $ids[] = $i+$id;
  71 + }
  72 + $id = end($ids);
  73 +
  74 + redis()->rPush('hot_check_ids',implode(',',$ids));
  75 +
  76 + if($id>$maxId){
  77 + break;
59 } 78 }
  79 + }
60 80
61 - }catch (Throwable $e){} 81 + redis()->set('hot_mail_sync',1,60);
62 } 82 }
63 83
64 84
65 - $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");  
66 - $id = 0;  
67 while (1){ 85 while (1){
68 - $ids = [];  
69 - for ($i=0;$i<1000;$i++){  
70 - $ids[] = $i+$id;  
71 - }  
72 - $id = end($ids);  
73 -  
74 - $this->run($ids);  
75 - if($id>$maxId){  
76 - break; 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);
77 } 93 }
78 } 94 }
79 95
80 96
  97 +
  98 +
81 echo '已执行完成'.PHP_EOL; 99 echo '已执行完成'.PHP_EOL;
82 } 100 }
83 101
@@ -98,7 +116,7 @@ class HotMail { @@ -98,7 +116,7 @@ class HotMail {
98 $w = ['email' =>$item['from']]; 116 $w = ['email' =>$item['from']];
99 } 117 }
100 // 是否在 预热邮箱中 118 // 是否在 预热邮箱中
101 - if($this->db->count('select count(*) from `hot_mail` where '.dbWhere($w))){ 119 + if($this->db->cache(300)->count('select count(*) from `hot_mail` where '.dbWhere($w))){
102 120
103 $ret = $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$item['id']])); 121 $ret = $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$item['id']]));
104 echo date('d H:i:s').' ==》 '.$item['id'].':'.$ret."\n"; 122 echo date('d H:i:s').' ==》 '.$item['id'].':'.$ret."\n";
@@ -156,7 +174,7 @@ swoole_set_process_name('hot-email-run-man'); @@ -156,7 +174,7 @@ swoole_set_process_name('hot-email-run-man');
156 174
157 $pm = new Swoole\Process\Manager(); 175 $pm = new Swoole\Process\Manager();
158 176
159 -$pm->add(function (){ 177 +$pm->addBatch(10,function (){
160 178
161 swoole_set_process_name('hot-email-run'); 179 swoole_set_process_name('hot-email-run');
162 180
@@ -165,7 +183,7 @@ $pm->add(function (){ @@ -165,7 +183,7 @@ $pm->add(function (){
165 new HotMail(); 183 new HotMail();
166 // 执行完了暂停5分钟在执行 184 // 执行完了暂停5分钟在执行
167 sleep(300); 185 sleep(300);
168 -}); 186 +},true);
169 187
170 $pm->start(); 188 $pm->start();
171 189