Scalr\System\Zmq\Cron\AbstractTask::launchWorkers PHP Метод

launchWorkers() защищенный Метод

It launches pool of workers
protected launchWorkers ( string $address = null ) : integer
$address string optional An address to override the service name
Результат integer The number of launched workers
    protected function launchWorkers($address = null)
    {
        $config = $this->config();
        //Wheter this service does not implement payload router interface
        if (!in_array('Scalr\\System\\Zmq\\Cron\\PayloadRouterInterface', class_implements($this->payloadClass))) {
            return $this->_launchWorkers($address);
        }
        $numberWorkers = 0;
        //It launches different pools of workers according to replication schema defined in the config
        foreach (array_merge(!empty($config->replicate['type']) ? $config->replicate['type'] : [], ['all']) as $type) {
            //It is possible to provide the number of the workers for each service
            $pool = null;
            if (is_array($type)) {
                @(list($type, $pool) = $type);
                $pool = $pool ?: intval($pool);
            }
            if (!empty($config->replicate['account'])) {
                foreach ($config->replicate['account'] as $acc) {
                    $pool2 = null;
                    if (is_array($acc)) {
                        @(list($acc, $pool2) = $acc);
                        $pool2 = $pool2 ?: intval($pool2);
                    }
                    $numberWorkers += $this->_launchWorkers($this->name . '.' . $type . '.' . $acc, max($pool, $pool2));
                }
            }
            $numberWorkers += $this->_launchWorkers($this->name . '.' . $type . '.all', $pool);
        }
        return $numberWorkers;
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\System\Zmq\Cron\AbstractTask::launchWorkers()
  */
 protected function launchWorkers($address = null)
 {
     $config = $this->config();
     //It launches different pools of workers according to replication schema defined in the config
     foreach (array_merge(!empty($config->replicate['type']) ? $config->replicate['type'] : [], ['all']) as $type) {
         if (!empty($config->replicate['account'])) {
             foreach ($config->replicate['account'] as $acc) {
                 parent::launchWorkers($this->name . '.' . $type . '.' . $acc);
             }
         }
         parent::launchWorkers($this->name . '.' . $type . '.all');
     }
 }