...
|
...
|
@@ -15,7 +15,7 @@ function start(){ |
|
|
$pm = new Process\Manager();
|
|
|
|
|
|
// 启动业务进程
|
|
|
$pm->addBatch(15,function (Process\Pool $pool, int $worker_id){
|
|
|
$pm->addBatch(30,function (Process\Pool $pool, int $worker_id){
|
|
|
|
|
|
swoole_set_process_name('php-email-sync-list-'.$worker_id);
|
|
|
|
...
|
...
|
@@ -23,6 +23,7 @@ function start(){ |
|
|
_echo("业务进程({$worker_id})启动成功");
|
|
|
|
|
|
$run_timer = time();
|
|
|
$goNum = 0;
|
|
|
// 循环阻塞
|
|
|
while (true){
|
|
|
|
...
|
...
|
@@ -38,8 +39,8 @@ function start(){ |
|
|
// 占用当前的id,占用2小时
|
|
|
if(redis()->add('just_sync_'.$id,time(),600)){
|
|
|
// 启动一个协程
|
|
|
go(function () use ($id){
|
|
|
|
|
|
go(function () use ($id,&$goNum){
|
|
|
$goNum++;
|
|
|
try{
|
|
|
// 开始同步
|
|
|
(new \Service\SyncMail($id))->sync();
|
...
|
...
|
@@ -49,7 +50,8 @@ function start(){ |
|
|
|
|
|
|
|
|
// 协程完成后执行的函数
|
|
|
co::defer(function () use ($id){
|
|
|
co::defer(function () use ($id,&$goNum){
|
|
|
$goNum--;
|
|
|
// 30秒后 消除占用
|
|
|
redis()->expire('just_sync_'.$id,60);
|
|
|
// 写入日志
|
...
|
...
|
@@ -57,6 +59,10 @@ function start(){ |
|
|
});
|
|
|
|
|
|
});
|
|
|
while ($goNum == 0){
|
|
|
co::sleep(0.5);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
co::sleep(1);
|
...
|
...
|
|