正在显示
1 个修改的文件
包含
25 行增加
和
44 行删除
@@ -8,57 +8,36 @@ | @@ -8,57 +8,36 @@ | ||
8 | 8 | ||
9 | use Swoole\Process; | 9 | use Swoole\Process; |
10 | 10 | ||
11 | - | 11 | +include_once __DIR__."/../vendor/autoload.php"; |
12 | 12 | ||
13 | function start(){ | 13 | function start(){ |
14 | 14 | ||
15 | -// 删除停止运行的值 | ||
16 | -// redis()->delete(SYNC_RUNNING_REDIS_KEY,'email_sync_stop_num'); | ||
17 | - | ||
18 | - // 进程管理器 | ||
19 | - $pm = new Process\Manager(); | ||
20 | - | ||
21 | - // 启动业务进程 | ||
22 | - $pm->addBatch(1,function (Process\Pool $pool, int $worker_id){ | ||
23 | - | ||
24 | - swoole_set_process_name('php-email-sync-list-check-'.$worker_id); | 15 | + swoole_set_process_name('php-email-sync-list-check'); |
25 | 16 | ||
26 | - include_once __DIR__."/../vendor/autoload.php"; | ||
27 | - _echo("业务进程({$worker_id})启动成功"); | 17 | + $id = 0; |
18 | + // 循环阻塞 | ||
19 | + while (true){ | ||
28 | 20 | ||
21 | + $id = db()->value('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' order by `id` asc limit 1'); | ||
29 | 22 | ||
30 | - $id = 0; | ||
31 | - // 循环阻塞 | ||
32 | - while (true){ | ||
33 | - | ||
34 | - $id = db()->value('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' order by `id` asc limit 1'); | 23 | + if($id){ |
24 | + // 启动一个协程 | ||
25 | + go(function () use ($id){ | ||
26 | + // 开始同步 | ||
27 | + try { | ||
28 | + sync($id); | ||
29 | + }catch (\Throwable $e){ | ||
30 | + echo $e->getMessage(); | ||
31 | + } | ||
32 | + \Lib\Log::getInstance()->write(); | ||
33 | + }); | ||
35 | 34 | ||
36 | - if($id){ | ||
37 | - // 占用当前的id,占用2小时 | ||
38 | - // if(redis()->add('just_sync_delete_'.$id,time(),3600)){ | ||
39 | - // 启动一个协程 | ||
40 | - go(function () use ($id){ | ||
41 | - // 开始同步 | ||
42 | - try { | ||
43 | - sync($id); | ||
44 | - }catch (\Throwable $e){ | ||
45 | - echo $e->getMessage(); | ||
46 | - } | ||
47 | - \Lib\Log::getInstance()->write(); | ||
48 | - }); | ||
49 | - // } | ||
50 | - }else{ | ||
51 | - //每次都暂停1秒,防止同一时间启动太多的任务 | ||
52 | - co::sleep(300); | ||
53 | - break; | ||
54 | - } | 35 | + }else{ |
36 | + //每次都暂停1秒,防止同一时间启动太多的任务 | ||
37 | + co::sleep(300); | ||
38 | + break; | ||
55 | } | 39 | } |
56 | - | ||
57 | - },true); | ||
58 | - | ||
59 | - | ||
60 | - // 启动管理器 | ||
61 | - $pm->start(); | 40 | + } |
62 | 41 | ||
63 | } | 42 | } |
64 | 43 | ||
@@ -166,8 +145,10 @@ if(!function_exists("imap_8bit")){ | @@ -166,8 +145,10 @@ if(!function_exists("imap_8bit")){ | ||
166 | } | 145 | } |
167 | 146 | ||
168 | 147 | ||
148 | +\Co\run(function (){ | ||
149 | + start(); | ||
150 | +}); | ||
169 | 151 | ||
170 | -start(); | ||
171 | 152 | ||
172 | 153 | ||
173 | 154 |
-
请 注册 或 登录 后发表评论