正在显示
1 个修改的文件
包含
18 行增加
和
41 行删除
@@ -7,59 +7,36 @@ use Swoole\Process; | @@ -7,59 +7,36 @@ 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){ | 16 | +while (1){ |
17 | + $id = redis()->lPop('sync_email_lists'); | ||
18 | + if($id && is_numeric($id)){ | ||
19 | + // 占用当前的id,占用2小时 | ||
20 | + if(redis()->add('just_sync_'.$id,time(),600)){ | ||
21 | + // 启动一个协程 | ||
22 | + | ||
23 | + try{ | ||
24 | + // 开始同步 | ||
25 | + (new \Service\SyncMail($id))->sync(); | ||
26 | + }catch (Throwable $e){ | ||
27 | + logs('sync : '.$e->getMessage()); | ||
28 | + } | ||
19 | 29 | ||
20 | - if($goNum>=50){ | ||
21 | - break; | ||
22 | - } | ||
23 | 30 | ||
24 | - // 需要同步的id | ||
25 | - $id = redis()->lPop('sync_email_lists'); | ||
26 | - | ||
27 | - if($id && is_numeric($id)){ | ||
28 | - // 占用当前的id,占用2小时 | ||
29 | - if(redis()->add('just_sync_'.$id,time(),600)){ | ||
30 | - // 启动一个协程 | ||
31 | - go(function () use ($id,&$goNum){ | ||
32 | - $goNum++; | ||
33 | - try{ | ||
34 | - // 开始同步 | ||
35 | - (new \Service\SyncMail($id))->sync(); | ||
36 | - }catch (Throwable $e){ | ||
37 | - logs('sync : '.$e->getMessage()); | ||
38 | - } | ||
39 | - | ||
40 | - | ||
41 | - // 协程完成后执行的函数 | ||
42 | - co::defer(function () use ($id,&$goNum){ | ||
43 | - $goNum--; | ||
44 | - // 30秒后 消除占用 | ||
45 | - redis()->expire('just_sync_'.$id,60); | ||
46 | - // 写入日志 | ||
47 | - \Lib\Log::getInstance()->write(); | ||
48 | - }); | ||
49 | - | ||
50 | - }); | 31 | + // 30秒后 消除占用 |
32 | + redis()->expire('just_sync_'.$id,60); | ||
51 | 33 | ||
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 |
-
请 注册 或 登录 后发表评论