public function run($tasks, $servers, $environments, $input, $output)
{
$this->tasks = $tasks;
$this->servers = $servers;
$this->environments = $environments;
$this->input = $input;
$this->output = new OutputWatcher($output);
$this->informer = new Informer($this->output);
$this->localhost = new Local();
$this->localEnv = new Environment();
$this->port = self::START_PORT;
connect:
$this->pure = new Server($this->port);
$this->loop = $this->pure->getLoop();
// Start workers for each server.
$this->loop->addTimer(0, [$this, 'startWorkers']);
// Wait for output
$this->outputStorage = $this->pure['output'] = new QueueStorage();
$this->loop->addPeriodicTimer(0, [$this, 'catchOutput']);
// Lookup for exception
$this->exceptionStorage = $this->pure['exception'] = new QueueStorage();
$this->loop->addPeriodicTimer(0, [$this, 'catchExceptions']);
// Send workers tasks to do.
$this->loop->addPeriodicTimer(0, [$this, 'sendTasks']);
// Wait all workers finish they tasks.
$this->loop->addPeriodicTimer(0, [$this, 'idle']);
// Start loop
try {
$this->pure->run();
} catch (ConnectionException $exception) {
// If port is already used, try with another one.
$output->writeln("<fg=red>✘ " . $exception->getMessage() . "</fg=red>");
if (++$this->port <= self::STOP_PORT) {
goto connect;
}
}
if (!$this->isSuccessfullyFinished) {
throw new \RuntimeException($this->lastExceptionMessage);
}
}