...
|
...
|
@@ -7,59 +7,36 @@ use Swoole\Process; |
|
|
include_once __DIR__."/../vendor/autoload.php";
|
|
|
|
|
|
exec("ps -aux|grep -E \"mail-serve-sync-list\" -c",$exec);
|
|
|
if(intval($exec[0]) > 50){
|
|
|
if(intval($exec[0]) > 200){
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
swoole_set_process_name("mail-serve-sync-list");
|
|
|
|
|
|
\Co\run(function (){
|
|
|
$goNum = 0;
|
|
|
while (true){
|
|
|
while (1){
|
|
|
$id = redis()->lPop('sync_email_lists');
|
|
|
if($id && is_numeric($id)){
|
|
|
// 占用当前的id,占用2小时
|
|
|
if(redis()->add('just_sync_'.$id,time(),600)){
|
|
|
// 启动一个协程
|
|
|
|
|
|
try{
|
|
|
// 开始同步
|
|
|
(new \Service\SyncMail($id))->sync();
|
|
|
}catch (Throwable $e){
|
|
|
logs('sync : '.$e->getMessage());
|
|
|
}
|
|
|
|
|
|
if($goNum>=50){
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
// 需要同步的id
|
|
|
$id = redis()->lPop('sync_email_lists');
|
|
|
|
|
|
if($id && is_numeric($id)){
|
|
|
// 占用当前的id,占用2小时
|
|
|
if(redis()->add('just_sync_'.$id,time(),600)){
|
|
|
// 启动一个协程
|
|
|
go(function () use ($id,&$goNum){
|
|
|
$goNum++;
|
|
|
try{
|
|
|
// 开始同步
|
|
|
(new \Service\SyncMail($id))->sync();
|
|
|
}catch (Throwable $e){
|
|
|
logs('sync : '.$e->getMessage());
|
|
|
}
|
|
|
|
|
|
|
|
|
// 协程完成后执行的函数
|
|
|
co::defer(function () use ($id,&$goNum){
|
|
|
$goNum--;
|
|
|
// 30秒后 消除占用
|
|
|
redis()->expire('just_sync_'.$id,60);
|
|
|
// 写入日志
|
|
|
\Lib\Log::getInstance()->write();
|
|
|
});
|
|
|
|
|
|
});
|
|
|
// 30秒后 消除占用
|
|
|
redis()->expire('just_sync_'.$id,60);
|
|
|
|
|
|
}
|
|
|
}else{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
while ($goNum == 0){
|
|
|
co::sleep(0.5);
|
|
|
break;
|
|
|
}
|
|
|
});
|
|
|
sleep(1);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|