正在显示
1 个修改的文件
包含
23 行增加
和
5 行删除
| @@ -41,6 +41,7 @@ class HotMail { | @@ -41,6 +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)){ | ||
| 44 | $fob = $this->getFobHotEmail(); | 45 | $fob = $this->getFobHotEmail(); |
| 45 | 46 | ||
| 46 | // 把黑格自己的也算进去 | 47 | // 把黑格自己的也算进去 |
| @@ -61,7 +62,6 @@ class HotMail { | @@ -61,7 +62,6 @@ class HotMail { | ||
| 61 | }catch (Throwable $e){} | 62 | }catch (Throwable $e){} |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | - | ||
| 65 | $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); | 65 | $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); |
| 66 | $id = 0; | 66 | $id = 0; |
| 67 | while (1){ | 67 | while (1){ |
| @@ -71,12 +71,30 @@ class HotMail { | @@ -71,12 +71,30 @@ class HotMail { | ||
| 71 | } | 71 | } |
| 72 | $id = end($ids); | 72 | $id = end($ids); |
| 73 | 73 | ||
| 74 | - $this->run($ids); | 74 | + redis()->rPush('hot_check_ids',implode(',',$ids)); |
| 75 | + | ||
| 75 | if($id>$maxId){ | 76 | if($id>$maxId){ |
| 76 | break; | 77 | break; |
| 77 | } | 78 | } |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 81 | + redis()->set('hot_mail_sync',1,60); | ||
| 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 | + | ||
| 80 | 98 | ||
| 81 | echo '已执行完成'.PHP_EOL; | 99 | echo '已执行完成'.PHP_EOL; |
| 82 | } | 100 | } |
| @@ -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 |
-
请 注册 或 登录 后发表评论