修复创建最大进程数目之后可继续创建
This commit is contained in:
parent
9335556197
commit
c84d5a2a17
@ -23,14 +23,21 @@ class Master
|
|||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $maxNum = 10;
|
protected $maxNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 常驻 process
|
* 常驻 process
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $staticNum = 1;
|
protected $staticNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临时进程数量
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $temporaryNum = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储 process 信息
|
* 存储 process 信息
|
||||||
@ -58,15 +65,6 @@ class Master
|
|||||||
*/
|
*/
|
||||||
protected $master_start_at;
|
protected $master_start_at;
|
||||||
|
|
||||||
|
|
||||||
protected $table;
|
|
||||||
/**
|
|
||||||
* 日志
|
|
||||||
*
|
|
||||||
* @var
|
|
||||||
*/
|
|
||||||
protected $logHandle;
|
|
||||||
|
|
||||||
// 版本
|
// 版本
|
||||||
const VERSION = '1.0.0';
|
const VERSION = '1.0.0';
|
||||||
|
|
||||||
@ -157,14 +155,29 @@ class Master
|
|||||||
*/
|
*/
|
||||||
protected function createProcess(Cron $cron)
|
protected function createProcess(Cron $cron)
|
||||||
{
|
{
|
||||||
$process = new Process(function (Process $process) use($cron) {
|
if ($this->isCanCreateTemporaryProcess()) {
|
||||||
$cron->run();
|
$process = new Process(function (Process $process) use ($cron) {
|
||||||
$process->exit();
|
$cron->run();
|
||||||
});
|
$process->exit();
|
||||||
|
});
|
||||||
|
|
||||||
// $process->name(sprintf('worker: '));
|
// $process->name(sprintf('worker: '));
|
||||||
|
|
||||||
$process->start();
|
$process->start();
|
||||||
|
|
||||||
|
$this->temporaryNum += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可以创建临时进程
|
||||||
|
*
|
||||||
|
* @time 2020年07月09日
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isCanCreateTemporaryProcess()
|
||||||
|
{
|
||||||
|
return ($this->table->count() + $this->temporaryNum) < $this->maxNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +98,7 @@ trait Process
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取相应的状态
|
// 获取相应的进程投递任务
|
||||||
if (isset($this->processes[$pid])) {
|
if (isset($this->processes[$pid])) {
|
||||||
return [true, $this->processes[$pid]];
|
return [true, $this->processes[$pid]];
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,8 @@ trait RegisterSignal
|
|||||||
$this->unsetWorkerStatus($res['pid']);
|
$this->unsetWorkerStatus($res['pid']);
|
||||||
unset($this->processes[$res['pid']]);
|
unset($this->processes[$res['pid']]);
|
||||||
}
|
}
|
||||||
|
// 临时进程数目减少一次
|
||||||
|
$this->temporaryNum -= 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user