/** * 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(); } } }
/** * {@inheritdoc} */ public function run($tasks, $servers, $environments, $input, $output) { $output = new OutputWatcher($output); $informer = new Informer($output); foreach ($tasks as $task) { $success = true; $informer->startTask($task->getName()); if ($task->isOnce()) { $task->run(new Context(null, null, $input, $output)); } else { foreach ($servers as $serverName => $server) { if ($task->runOnServer($serverName)) { $env = isset($environments[$serverName]) ? $environments[$serverName] : ($environments[$serverName] = new Environment()); $informer->onServer($serverName); try { $task->run(new Context($server, $env, $input, $output)); } catch (NonFatalException $exception) { $success = false; $informer->taskException($serverName, 'Deployer\\Task\\NonFatalException', $exception->getMessage()); } $informer->endOnServer($serverName); } } } if ($success) { $informer->endTask(); } else { $informer->taskError(); } } }
/** * 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(); } } }
public function testInformer() { $output = $this->getMockBuilder('Deployer\\Console\\Output\\OutputWatcher')->disableOriginalConstructor()->setMethods(['getVerbosity', 'getWasWritten', 'write'])->getMock(); $output->expects($this->any())->method('getVerbosity')->will($this->returnValue(OutputInterface::VERBOSITY_NORMAL)); $informer = new Informer($output); // TODO: Check something. $informer->startTask('task'); $informer->onServer('server'); $informer->endTask(); }