| 
...
 | 
...
 | 
@@ -26,15 +26,17 @@ function start(){ | 
| 
 | 
 | 
         // 循环阻塞
 | 
| 
 | 
 | 
         while (true){
 | 
| 
 | 
 | 
             while ($goNum > 50){
 | 
| 
 | 
 | 
                 co::sleep(0.3);
 | 
| 
 | 
 | 
                 co::sleep(0.5);
 | 
| 
 | 
 | 
                 continue;
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
             // 需要同步的id
 | 
| 
 | 
 | 
             $id = redis()->lPop('sync_email_lists');
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             if($id && is_numeric($id)){
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
                 // 占用当前的id,占用2小时
 | 
| 
 | 
 | 
                 if(redis()->add('just_sync_'.$id,time(),600)){
 | 
| 
 | 
 | 
                     redis()->set('sync_my_pid:'.getmypid(),time(),86400);
 | 
| 
 | 
 | 
                     // 启动一个协程
 | 
| 
 | 
 | 
                     go(function () use ($id,&$goNum){
 | 
| 
 | 
 | 
                         $goNum++;
 | 
| 
...
 | 
...
 | 
@@ -73,7 +75,7 @@ function start(){ | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             //每次都暂停1秒,防止同一时间启动太多的任务
 | 
| 
 | 
 | 
             co::sleep(0.1);
 | 
| 
 | 
 | 
             co::sleep(1);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
...
 | 
...
 | 
 |