/**
* {@inheritdoc}
*/
protected function execute(Input $input, Output $output)
{
$stage = $input->hasArgument('stage') ? $input->getArgument('stage') : null;
$tasks = $this->deployer->getScriptManager()->getTasks($this->getName(), $stage);
$servers = $this->deployer->getStageStrategy()->getServers($stage);
$environments = iterator_to_array($this->deployer->environments);
if (isset($this->executor)) {
$executor = $this->executor;
} else {
if ($input->getOption('parallel')) {
$executor = new ParallelExecutor($this->deployer->getConsole()->getUserDefinition());
} else {
$executor = new SeriesExecutor();
}
}
try {
$executor->run($tasks, $servers, $environments, $input, $output);
} catch (\Exception $exception) {
\Deployer\logger($exception->getMessage(), Logger::ERROR);
// Check if we have tasks to execute on failure.
if ($this->deployer['onFailure']->has($this->getName())) {
$taskName = $this->deployer['onFailure']->get($this->getName());
$tasks = $this->deployer->getScriptManager()->getTasks($taskName, $stage);
$executor->run($tasks, $servers, $environments, $input, $output);
}
throw $exception;
}
if (Deployer::hasDefault('terminate_message')) {
$output->writeln(Deployer::getDefault('terminate_message'));
}
}