/** * Action time for master! Send tasks `to-do` for workers and go to sleep. * Also decide when to stop server/loop. */ public function sendTasks() { if (!$this->wait) { if (count($this->tasks) > 0) { // Get task name to do. $task = current($this->tasks); $taskName = $task->getName(); array_shift($this->tasks); $this->informer->startTask($taskName); if ($task->isOnce()) { $task->run(new Context($this->localhost, $this->localEnv, $this->input, $this->output)); $this->informer->endTask(); } else { $this->tasksToDo = []; foreach ($this->servers as $serverName => $server) { if ($task->isOnServer($serverName)) { if (!isset($this->environments[$serverName])) { $this->environments[$serverName] = new Environment(); } // Start task on $serverName. $this->tasksToDo[$serverName] = $taskName; } } // Inform all workers what tasks they need to do. $taskToDoStorage = new ArrayStorage(); $taskToDoStorage->push($this->tasksToDo); $this->pure->setStorage('tasks_to_do', $taskToDoStorage); $this->wait = true; } } else { $this->loop->stop(); } } }
/** * Action time for master! Send tasks `to-do` for workers and go to sleep. * Also decide when to stop server/loop. */ public function sendTasks() { if (!$this->wait) { if (count($this->tasks) > 0) { // Get task name to do. $task = current($this->tasks); $taskName = $task->getName(); array_shift($this->tasks); $this->informer->startTask($taskName); if ($task->isOnce()) { $task->run(new Context(null, null, $this->input, $this->output)); $this->informer->endTask(); } else { $this->tasksToDo = []; foreach ($this->servers as $serverName => $server) { if ($task->runOnServer($serverName)) { $env = isset($this->environments[$serverName]) ? $this->environments[$serverName] : ($this->environments[$serverName] = new Environment()); if (count($task->getOnlyForStage()) > 0 && (!$env->has('stages') || !$task->runForStages($env->get('stages')))) { continue; } $this->informer->onServer($serverName); $this->tasksToDo[$serverName] = $taskName; } } // Inform all workers what tasks they need to do. $taskToDoStorage = new ArrayStorage(); $taskToDoStorage->push($this->tasksToDo); $this->pure->setStorage('tasks_to_do', $taskToDoStorage); $this->wait = true; } } else { $this->loop->stop(); } } }