...
|
...
|
@@ -26,22 +26,16 @@ function start(){ |
|
|
include_once __DIR__."/../vendor/autoload.php";
|
|
|
_echo("业务进程({$worker_id})启动成功");
|
|
|
|
|
|
$run_timer = time();
|
|
|
|
|
|
$id = 0;
|
|
|
// 循环阻塞
|
|
|
while (true){
|
|
|
|
|
|
// 运行超过1天的 停止
|
|
|
if($run_timer < (time()-21600)){
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
$id = db()->value(\Model\listsSql::first('`id` > '.$id,'`id`'));
|
|
|
$id = db()->value('select `id` from `'.\Model\emailSql::$table.'` where `id` > '.$id.' limit 1');
|
|
|
|
|
|
if($id){
|
|
|
// 占用当前的id,占用2小时
|
|
|
if(redis()->add('just_sync_delete_'.$id,time(),3600)){
|
|
|
// if(redis()->add('just_sync_delete_'.$id,time(),3600)){
|
|
|
// 启动一个协程
|
|
|
go(function () use ($id){
|
|
|
// 开始同步
|
...
|
...
|
@@ -52,12 +46,12 @@ function start(){ |
|
|
}
|
|
|
\Lib\Log::getInstance()->write();
|
|
|
});
|
|
|
}
|
|
|
// }
|
|
|
}else{
|
|
|
co::sleep(1);
|
|
|
}
|
|
|
//每次都暂停1秒,防止同一时间启动太多的任务
|
|
|
co::sleep(0.5);
|
|
|
co::sleep(300);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
},true);
|
...
|
...
|
@@ -107,16 +101,20 @@ function sync($email_id){ |
|
|
$page = 0;
|
|
|
$db = db();
|
|
|
while (1){
|
|
|
$ids = $db->all("select `id`,`uid` from ".\Model\listsSql::$table." limit 100 offset ".($page*100));
|
|
|
$ids = $db->all("select `id`,`uid` from ".\Model\listsSql::$table." where `email_id` = {$email_id} and `folder_id` = {$folder_id} limit 100 offset ".($page*100));
|
|
|
$page++;
|
|
|
if($ids){
|
|
|
$ids = array_column($ids,'id','uid');
|
|
|
try {
|
|
|
$result = $mailServer->client->fetch(array_keys($ids),'UID',true);
|
|
|
}catch (Throwable $e){
|
|
|
return 0;
|
|
|
}
|
|
|
foreach ($ids as $uid=>$id){
|
|
|
if(!isset($result[$uid])){
|
|
|
_echo('删除 e '.$email_id.' f '.$folder_id.' u '.$uid.' id '.$id);
|
|
|
_echo('删除 e '.$email_id.' f '.$folder_id.' u '.$uid.' id '.$id.' d '.$db->delete(\Model\listsSql::$table,['id'=>$id]).' fd '.$db->delete('fob_hot_mail',['lists_id'=>$id]));
|
|
|
// 删除 如果远程没有,就删除本地
|
|
|
$db->delete(\Model\listsSql::$table,['id'=>$id]);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|