protected function updateManagerSet()
{
$queueStatsServer = $this->getQueue()->getStats();
if (!isset($queueStatsServer[Queue::STATS_QUEUES]) || count($queueStatsServer[Queue::STATS_QUEUES]) == 0) {
return $this;
}
/**
* filter if queue not stopped
* filter if queue has jobs
*/
$managerOptionsSet = [];
foreach ($queueStatsServer[Queue::STATS_QUEUES] as $workerClass => $queueStats) {
if (in_array($workerClass, $this->managerIgnoreSet)) {
continue;
}
if (!class_exists($workerClass)) {
$this->managerIgnoreSet[] = $workerClass;
continue;
}
if ($queueStats[Queue::STATS_QUEUE_STOP]) {
continue;
}
if ($queueStats[Queue::STATS_JOBS_READY] == 0) {
continue;
}
try {
/** @var AbstractWorker $workerClass */
$workerConfig = $workerClass::getConfig();
// we need threads ..
$managerCount = $this->calcManagerSize($queueStats[Queue::STATS_JOBS_READY], $workerConfig[AbstractWorker::CONFIG_P_MANAGER_POOL_SIZE], $workerConfig[AbstractWorker::CONFIG_P_MANAGERS_LIMIT]);
/** @var string $workerClass */
$managerOptionsSet[$workerClass] = $managerCount;
} catch (WorkerException $ex) {
$this->managerIgnoreSet[] = $workerClass;
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
$this->getLogger()->warning("Daemon {$this->getAppId()} will ignore worker class {$workerClass}", [__NAMESPACE__]);
continue;
} catch (\Exception $ex) {
$this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
continue;
}
}
if (count($managerOptionsSet) == 0) {
return $this;
}
$appId = $this->getAppId();
$bootstrapFile = $this->getConfig(self::CONFIG_BOOTSTRAP_FILE);
foreach ($managerOptionsSet as $workerClass => $managerCount) {
while ($managerCount--) {
$managerId = $this->buildManagerId($workerClass, $managerCount);
if (array_key_exists($managerId, $this->managerSet)) {
continue;
}
$this->getLogger()->debug("Daemon create manager : {$managerId}", [__NAMESPACE__]);
$this->managerSet[$managerId] = new Manager($managerId, $appId, $workerClass, $bootstrapFile);
}
}
return $this;
}