...
|
...
|
@@ -8,57 +8,36 @@ |
|
|
|
|
|
use Swoole\Process;
|
|
|
|
|
|
|
|
|
include_once __DIR__."/../vendor/autoload.php";
|
|
|
|
|
|
function start(){
|
|
|
|
|
|
// 删除停止运行的值
|
|
|
// redis()->delete(SYNC_RUNNING_REDIS_KEY,'email_sync_stop_num');
|
|
|
|
|
|
// 进程管理器
|
|
|
$pm = new Process\Manager();
|
|
|
|
|
|
// 启动业务进程
|
|
|
$pm->addBatch(1,function (Process\Pool $pool, int $worker_id){
|
|
|
|
|
|
swoole_set_process_name('php-email-sync-list-check-'.$worker_id);
|
|
|
swoole_set_process_name('php-email-sync-list-check');
|
|
|
|
|
|
include_once __DIR__."/../vendor/autoload.php";
|
|
|
_echo("业务进程({$worker_id})启动成功");
|
|
|
$id = 0;
|
|
|
// 循环阻塞
|
|
|
while (true){
|
|
|
|
|
|
$id = db()->value('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' order by `id` asc limit 1');
|
|
|
|
|
|
$id = 0;
|
|
|
// 循环阻塞
|
|
|
while (true){
|
|
|
|
|
|
$id = db()->value('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' order by `id` asc limit 1');
|
|
|
if($id){
|
|
|
// 启动一个协程
|
|
|
go(function () use ($id){
|
|
|
// 开始同步
|
|
|
try {
|
|
|
sync($id);
|
|
|
}catch (\Throwable $e){
|
|
|
echo $e->getMessage();
|
|
|
}
|
|
|
\Lib\Log::getInstance()->write();
|
|
|
});
|
|
|
|
|
|
if($id){
|
|
|
// 占用当前的id,占用2小时
|
|
|
// if(redis()->add('just_sync_delete_'.$id,time(),3600)){
|
|
|
// 启动一个协程
|
|
|
go(function () use ($id){
|
|
|
// 开始同步
|
|
|
try {
|
|
|
sync($id);
|
|
|
}catch (\Throwable $e){
|
|
|
echo $e->getMessage();
|
|
|
}
|
|
|
\Lib\Log::getInstance()->write();
|
|
|
});
|
|
|
// }
|
|
|
}else{
|
|
|
//每次都暂停1秒,防止同一时间启动太多的任务
|
|
|
co::sleep(300);
|
|
|
break;
|
|
|
}
|
|
|
}else{
|
|
|
//每次都暂停1秒,防止同一时间启动太多的任务
|
|
|
co::sleep(300);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
},true);
|
|
|
|
|
|
|
|
|
// 启动管理器
|
|
|
$pm->start();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -166,8 +145,10 @@ if(!function_exists("imap_8bit")){ |
|
|
}
|
|
|
|
|
|
|
|
|
\Co\run(function (){
|
|
|
start();
|
|
|
});
|
|
|
|
|
|
start();
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|