作者 邓超

x

... ... @@ -41,43 +41,61 @@ class HotMail {
private function start(){
_echo('启动预热邮件处理 '.getmypid());
$fob = $this->getFobHotEmail();
if(redis()->add('hot_mail_sync',1)){
$fob = $this->getFobHotEmail();
// 把黑格自己的也算进去
$this->shopkHotEmail = array_merge($this->getHotEmail('e'),$this->getHotEmail('w'),$fob);
// 把黑格自己的也算进去
$this->shopkHotEmail = array_merge($this->getHotEmail('e'),$this->getHotEmail('w'),$fob);
$this->shopkHotEmail = array_map('strtolower',$this->shopkHotEmail);
$this->shopkHotEmail = array_map('strtolower',$this->shopkHotEmail);
$this->shopkHotEmail = array_flip($this->shopkHotEmail);
$this->shopkHotEmail = array_flip($this->shopkHotEmail);
$this->shopkHotEmail['job@aicc-email.com'] = 1;
$this->shopkHotEmail['job@aicc-email.com'] = 1;
foreach ($this->shopkHotEmail as $e=>$i){
try {
if(!$this->db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$e]))){
$this->db->throw()->insert('hot_mail',['email'=>$e],false);
foreach ($this->shopkHotEmail as $e=>$i){
try {
if(!$this->db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$e]))){
$this->db->throw()->insert('hot_mail',['email'=>$e],false);
}
}catch (Throwable $e){}
}
$maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
$id = 0;
while (1){
$ids = [];
for ($i=0;$i<1000;$i++){
$ids[] = $i+$id;
}
$id = end($ids);
redis()->rPush('hot_check_ids',implode(',',$ids));
if($id>$maxId){
break;
}
}
}catch (Throwable $e){}
redis()->set('hot_mail_sync',1,60);
}
$maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
$id = 0;
while (1){
$ids = [];
for ($i=0;$i<1000;$i++){
$ids[] = $i+$id;
}
$id = end($ids);
$this->run($ids);
if($id>$maxId){
break;
$ids = redis()->lPop('hot_check_ids');
if($ids){
$ids = explode(',',$ids);
$this->run($ids);
}else{
echo '等待'.PHP_EOL;
co::sleep(2);
}
}
echo '已执行完成'.PHP_EOL;
}
... ... @@ -98,7 +116,7 @@ class HotMail {
$w = ['email' =>$item['from']];
}
// 是否在 预热邮箱中
if($this->db->count('select count(*) from `hot_mail` where '.dbWhere($w))){
if($this->db->cache(300)->count('select count(*) from `hot_mail` where '.dbWhere($w))){
$ret = $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$item['id']]));
echo date('d H:i:s').' ==》 '.$item['id'].':'.$ret."\n";
... ... @@ -156,7 +174,7 @@ swoole_set_process_name('hot-email-run-man');
$pm = new Swoole\Process\Manager();
$pm->add(function (){
$pm->addBatch(10,function (){
swoole_set_process_name('hot-email-run');
... ... @@ -165,7 +183,7 @@ $pm->add(function (){
new HotMail();
// 执行完了暂停5分钟在执行
sleep(300);
});
},true);
$pm->start();
... ...