正在显示
1 个修改的文件
包含
5 行增加
和
28 行删除
| @@ -7,29 +7,19 @@ use Swoole\Process; | @@ -7,29 +7,19 @@ use Swoole\Process; | ||
| 7 | include_once __DIR__."/../vendor/autoload.php"; | 7 | include_once __DIR__."/../vendor/autoload.php"; |
| 8 | 8 | ||
| 9 | exec("ps -aux|grep -E \"mail-serve-sync-list\" -c",$exec); | 9 | exec("ps -aux|grep -E \"mail-serve-sync-list\" -c",$exec); |
| 10 | -if(intval($exec[0]) > 50){ | 10 | +if(intval($exec[0]) > 200){ |
| 11 | exit; | 11 | exit; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | swoole_set_process_name("mail-serve-sync-list"); | 14 | swoole_set_process_name("mail-serve-sync-list"); |
| 15 | 15 | ||
| 16 | -\Co\run(function (){ | ||
| 17 | - $goNum = 0; | ||
| 18 | - while (true){ | ||
| 19 | - | ||
| 20 | - if($goNum>=50){ | ||
| 21 | - break; | ||
| 22 | - } | ||
| 23 | - | ||
| 24 | - // 需要同步的id | 16 | +while (1){ |
| 25 | $id = redis()->lPop('sync_email_lists'); | 17 | $id = redis()->lPop('sync_email_lists'); |
| 26 | - | ||
| 27 | if($id && is_numeric($id)){ | 18 | if($id && is_numeric($id)){ |
| 28 | // 占用当前的id,占用2小时 | 19 | // 占用当前的id,占用2小时 |
| 29 | if(redis()->add('just_sync_'.$id,time(),600)){ | 20 | if(redis()->add('just_sync_'.$id,time(),600)){ |
| 30 | // 启动一个协程 | 21 | // 启动一个协程 |
| 31 | - go(function () use ($id,&$goNum){ | ||
| 32 | - $goNum++; | 22 | + |
| 33 | try{ | 23 | try{ |
| 34 | // 开始同步 | 24 | // 开始同步 |
| 35 | (new \Service\SyncMail($id))->sync(); | 25 | (new \Service\SyncMail($id))->sync(); |
| @@ -38,28 +28,15 @@ swoole_set_process_name("mail-serve-sync-list"); | @@ -38,28 +28,15 @@ swoole_set_process_name("mail-serve-sync-list"); | ||
| 38 | } | 28 | } |
| 39 | 29 | ||
| 40 | 30 | ||
| 41 | - // 协程完成后执行的函数 | ||
| 42 | - co::defer(function () use ($id,&$goNum){ | ||
| 43 | - $goNum--; | ||
| 44 | // 30秒后 消除占用 | 31 | // 30秒后 消除占用 |
| 45 | redis()->expire('just_sync_'.$id,60); | 32 | redis()->expire('just_sync_'.$id,60); |
| 46 | - // 写入日志 | ||
| 47 | - \Lib\Log::getInstance()->write(); | ||
| 48 | - }); | ||
| 49 | 33 | ||
| 50 | - }); | ||
| 51 | - | ||
| 52 | - } | ||
| 53 | - }else{ | ||
| 54 | break; | 34 | break; |
| 55 | } | 35 | } |
| 56 | } | 36 | } |
| 57 | 37 | ||
| 58 | - while ($goNum == 0){ | ||
| 59 | - co::sleep(0.5); | ||
| 60 | - break; | ||
| 61 | - } | ||
| 62 | -}); | 38 | + sleep(1); |
| 39 | +} | ||
| 63 | 40 | ||
| 64 | 41 | ||
| 65 | 42 |
-
请 注册 或 登录 后发表评论