正在显示
1 个修改的文件
包含
6 行增加
和
25 行删除
| @@ -8,24 +8,11 @@ | @@ -8,24 +8,11 @@ | ||
| 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); | ||
| 25 | - | ||
| 26 | - include_once __DIR__."/../vendor/autoload.php"; | ||
| 27 | - _echo("业务进程({$worker_id})启动成功"); | ||
| 28 | - | 15 | + swoole_set_process_name('php-email-sync-list-check'); | 
| 29 | 16 | ||
| 30 | $id = 0; | 17 | $id = 0; | 
| 31 | // 循环阻塞 | 18 | // 循环阻塞 | 
| @@ -34,8 +21,6 @@ function start(){ | @@ -34,8 +21,6 @@ function start(){ | ||
| 34 | $id = db()->value('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' order by `id` asc limit 1'); | 21 | $id = db()->value('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' order by `id` asc limit 1'); | 
| 35 | 22 | ||
| 36 | if($id){ | 23 | if($id){ | 
| 37 | - // 占用当前的id,占用2小时 | ||
| 38 | - // if(redis()->add('just_sync_delete_'.$id,time(),3600)){ | ||
| 39 | // 启动一个协程 | 24 | // 启动一个协程 | 
| 40 | go(function () use ($id){ | 25 | go(function () use ($id){ | 
| 41 | // 开始同步 | 26 | // 开始同步 | 
| @@ -46,7 +31,7 @@ function start(){ | @@ -46,7 +31,7 @@ function start(){ | ||
| 46 | } | 31 | } | 
| 47 | \Lib\Log::getInstance()->write(); | 32 | \Lib\Log::getInstance()->write(); | 
| 48 | }); | 33 | }); | 
| 49 | - // } | 34 | + | 
| 50 | }else{ | 35 | }else{ | 
| 51 | //每次都暂停1秒,防止同一时间启动太多的任务 | 36 | //每次都暂停1秒,防止同一时间启动太多的任务 | 
| 52 | co::sleep(300); | 37 | co::sleep(300); | 
| @@ -54,12 +39,6 @@ function start(){ | @@ -54,12 +39,6 @@ function start(){ | ||
| 54 | } | 39 | } | 
| 55 | } | 40 | } | 
| 56 | 41 | ||
| 57 | - },true); | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - // 启动管理器 | ||
| 61 | - $pm->start(); | ||
| 62 | - | ||
| 63 | } | 42 | } | 
| 64 | 43 | ||
| 65 | /** | 44 | /** | 
| @@ -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 | 
- 
请 注册 或 登录 后发表评论