Добавляет воркер в балансировщик,
когда тот успешно стартует.

@param Worker $worker
@return bool
7762
public function addWorker(Worker $worker): bool
    {
        if (!$this->running) {
            return false;
        }
        $this->running = 0;
        $this->workerPool->add($worker);

        return true;
    }
1224190
public function finished(Worker $worker)
    {
        $this->redis->srem(self::redisKey($this), (string)$worker);
    }
279150
private function runQueue($queue, $worker)
    {
        $result['count'] = 0;
        $result['total'] = $queue->numberOfItems();
        while ($item = $queue->claimItem()) {
            try {
                $worker->processItem($item->data);
                $queue->deleteItem($item);
                $result['count']++;
            } catch (SuspendQueueException $e) {
                $queue->releaseItem($item);
                $result['error'] = $e;
            }
        }

        return $result;
    }
933654
public function work()
    {
        $workerNeed = self::WORKER_MIN * $this->workerMultiplier;
        $workerCount = count($this->workerPool);

        if (
            ($workerCount < $workerNeed && $workerCount < $this->workerMaxCount)
            && !$this->running
        ) {
            // run new worker
            $this->workerRun = $this->workerStarter->start();
            $this->running = time();
        } elseif ($this->running && $this->running < time() - 10) {
            // timeout 10 sec - не удалось запустить воркер
            $this->running = 0;
            if ($this->workerRun->isRunning()) {
                // убиваем запущенный процесс, если он ещё работает
                $this->workerRun->kill();
            }
        }
    }
706988
public function isWorker($worker_id = null)
    {
        if ($worker_id == null) {
            $worker_id = $this->workerId;
        }
        return $worker_id < $this->worker_num ? true : false;
    }
266872
def _dismiss_worker(self, worker):
        """"""
        self._workers.remove(worker)
        if len(self._workers) < self._min_workers:
            self._workers.add(worker)
            return False
        return True
821808
private function setWorkerID($workerID)
    {
        if ($workerID >= 1 &&
            $workerID <= 255
        ) {
            return (int)$workerID;
        } elseif ($workerID !== null) {
            throw new \InvalidArgumentException('WorkerID out of range (1-255)');
        }
        return rand(1, 255);
    }
613381
public function loadPicture($image, $worker = NULL)
    {
        if($this->pictureLoader)
        {
            return $this->pictureLoader->loadPicture($image, $this, $worker);
        }

        return new Picture($image, $this, $worker, $this->fallbackImage);
    }
1240008
public function startWorker(WorkerInterface $worker)
    {
        $parent = $this->system->createCurrentProcess();

        $this->eventDispatcher->dispatch(ResqueEvents::PRE_FORK);

        $child = $parent->fork();

        // This exists because workers that get reset after a crash still hold their old id.
        // @todo this shouldn't be needed if id was always derived.. hmm.
        $worker->setId(null);

        if (null === $child) {
            // This is spawned worker process, it will process jobs until told to exit.
            $this->eventDispatcher->dispatch(ResqueEvents::POST_FORK_CHILD);

            $worker->setProcess($this->system->createCurrentProcess());

            $this->registry->register($worker);
            $worker->work();
            $this->registry->deregister($worker);

            exit(0);
        }

        $this->eventDispatcher->dispatch(ResqueEvents::POST_FORK_PARENT);

        $worker->setProcess($child);

        $this->logger->info(
            'Successfully started worker {worker} with pid {childPid}',
            array(
                'worker' => $worker,
                'childPid' => $child->getPid(),
            )
        );
    }
848970
public function onWorkerComplete(WorkerInterface $worker)
    {
        $worker->free();
        $this->running = array_filter($this->running, function (WorkerInterface $worker) {
            return $worker->isRunning();
        });
    }
200057
public function create(): Worker
    {
        if (Parallel::isSupported()) {
            return new WorkerParallel($this->className);
        }

        if (Thread::isSupported()) {
            return new WorkerThread($this->className);
        }

        return new WorkerProcess(
            $this->className,
            [],
            \getenv("AMP_PHP_BINARY") ?: (\defined("AMP_PHP_BINARY") ? \AMP_PHP_BINARY : null)
        );
    }
1268993
public function restore($workerInstance)
    {
        list($hostname, $pid, $queues) = explode(':', $workerInstance, 3);
        if (!is_array($queues)) {
            $queues = explode(',', $queues);
        }

        $this->queues = $queues;
        $this->pid = $pid;
        $this->id = $workerInstance; //regenerate worker
        $data = $this->resqueInstance->redis->get($this->workerName() . ':' . $workerInstance);
        if ($data !== false) {
            $data = json_decode($data, true);
            $this->currentJob = new ResqueJobBase($this->resqueInstance, $data['queue'], $data['payload'], true);
        }
        $workerPids = self::workerPids();
        if (!in_array($pid, $workerPids)) {
            $this->unregisterWorker();
            return false;
        }
        return true;
    }
115462
private function workerHeader($worker_file_name, $envs = array())
    {
        $export_env = "";
        foreach ($envs as $env => $value) {
            $export_env .= "putenv(\"$env=$value\");\r\n";
        }
        $header = <<<EOL
<?php
/*IRON_WORKER_HEADER*/
$export_env
function getArgs(\$assoc = true)
{
    global \$argv;

    \$args = array('task_id' => null, 'dir' => null, 'payload' => array(), 'config' => null);

    foreach (\$argv as \$k => \$v)
    {
        if (empty(\$argv[\$k + 1]))
        {
            continue;
        }

        if (\$v == '-id') \$args['task_id'] = \$argv[\$k + 1];
        if (\$v == '-d') \$args['dir'] = \$argv[\$k + 1];
        if (\$v == '-payload') \$args['payload_file'] = \$argv[\$k + 1];
        if (\$v == '-config') \$args['config_file'] = \$argv[\$k + 1];
    }

    if (getenv('TASK_ID')) \$args['task_id'] = getenv('TASK_ID');
    if (getenv('TASK_DIR')) \$args['dir'] = getenv('TASK_DIR');
    if (getenv('PAYLOAD_FILE')) \$args['payload_file'] = getenv('PAYLOAD_FILE');
    if (getenv('CONFIG_FILE')) \$args['config_file'] = getenv('CONFIG_FILE');

    if (array_key_exists('payload_file',\$args) && file_exists(\$args['payload_file']))
    {
        \$args['payload'] = file_get_contents(\$args['payload_file']);

        \$parsed_payload = json_decode(\$args['payload'], \$assoc);

        if (\$parsed_payload != null)
        {
            \$args['payload'] = \$parsed_payload;
        }
    }

    if (array_key_exists('config_file',\$args) && file_exists(\$args['config_file']))
    {
        \$args['config'] = file_get_contents(\$args['config_file']);

        \$parsed_config = json_decode(\$args['config'], \$assoc);

        if (\$parsed_config != null)
        {
            \$args['config'] = \$parsed_config;
        }
    }

    return \$args;
}

function getPayload(\$assoc = false)
{
    \$args = getArgs(\$assoc);

    return \$args['payload'];
}

function getConfig(\$assoc = true)
{
    \$args = getArgs(\$assoc);

    return \$args['config'];
}

require dirname(__FILE__)."/[SCRIPT]";
EOL;
        $header = str_replace(
            array('[PROJECT_ID]', '[URL]', '[HEADERS]', '[SCRIPT]'),
            array($this->project_id, $this->url, var_export($this->compiledHeaders(), true), $worker_file_name),
            $header
        );
        return trim($header, " \n\r");
    }
771863
protected function pidIsValid(int $pid, string $workerName) : bool
    {
        $processInfo = exec(sprintf('ps -p %d -o args=', $pid));
        if (empty($processInfo)) {
            return false;
        }
        if (strpos($processInfo, $workerName) === false) {
            return false;
        }
        return true;
    }
699596
public function getWorkerForStream($stream)
    {
        foreach ($this->workers as $worker) {
            if ($worker->hasStream($stream)) {
                return $worker;
            }
        }

        return null;
    }
857800
public static function getWorkerID()
    {
        if(null === static::$workerID)
        {
            $main = ServerManage::getServer('main');
            if($main)
            {
                $workerID = $main->getSwooleServer()->worker_id;
                if($workerID > -1)
                {
                    static::$workerID = $workerID;
                }
            }
        }
        return static::$workerID;
    }
853363
def worker_status(worker, profile='default'):
    '''
    
    '''

    config = get_running(profile)
    try:
        return {
            'activation': config['worker.{0}.activation'.format(worker)],
            'state': config['worker.{0}.state'.format(worker)],
        }
    except KeyError:
        return False