src/Producer.php
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;
    }
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;
    }
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 ; }
Update Manager SET

REMEMBER queueName === workerClass (cause we have relation one queue name for one type of worker)

1) get Queue stats for all queues on server
2) filter queues (stopping flag / existing ready job in it)
3) get worker configuration (to know what manager balance should do later)
- if worker have problems with config we will add him to ignore manager set
4) then we try to create manager depend on exists managerSet and current balance

@return $this
Update Manager SET