正在显示
1 个修改的文件
包含
5 行增加
和
4 行删除
| @@ -34,10 +34,7 @@ function start(){ | @@ -34,10 +34,7 @@ function start(){ | ||
| 34 | // 需要同步的id | 34 | // 需要同步的id |
| 35 | $id = redis()->lPop('sync_email_lists'); | 35 | $id = redis()->lPop('sync_email_lists'); |
| 36 | 36 | ||
| 37 | - if(!$id || !is_numeric($id)){ | ||
| 38 | - co::sleep(1); | ||
| 39 | - } | ||
| 40 | - else{ | 37 | + if($id && is_numeric($id)){ |
| 41 | // 占用当前的id,占用2小时 | 38 | // 占用当前的id,占用2小时 |
| 42 | if(redis()->add('just_sync_'.$id,time(),600)){ | 39 | if(redis()->add('just_sync_'.$id,time(),600)){ |
| 43 | // 启动一个协程 | 40 | // 启动一个协程 |
| @@ -63,7 +60,11 @@ function start(){ | @@ -63,7 +60,11 @@ function start(){ | ||
| 63 | 60 | ||
| 64 | }); | 61 | }); |
| 65 | } | 62 | } |
| 63 | + }else{ | ||
| 64 | + co::sleep(1); | ||
| 66 | } | 65 | } |
| 66 | + //每次都暂停1秒,防止同一时间启动太多的任务 | ||
| 67 | + co::sleep(0.5); | ||
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | },true); | 70 | },true); |
-
请 注册 或 登录 后发表评论