From 6feaac17e0825095320f74e6c35df390e2555b8e Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Mon, 10 Jun 2024 11:14:32 +1200 Subject: [PATCH] fix: increase process timeout, stop dumping multiple output lines in stream results --- src/Beam.php | 11 +++++++---- src/Command/TransferCommand.php | 6 +++++- src/DeploymentProvider/Rsync.php | 9 +++++++-- src/Helper/DeploymentResultHelper.php | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Beam.php b/src/Beam.php index b746b43..b50cd1e 100644 --- a/src/Beam.php +++ b/src/Beam.php @@ -157,7 +157,6 @@ protected function validateSetup() "Commands are to run on the location 'target' but the deployment provider '{$server['type']}' cannot execute remote commands." ); } - } } @@ -489,6 +488,10 @@ public function getLocalPathFolder(): string */ public function getProcess($commandline, $cwd = null, $timeout = null): Process { + if (!$timeout) { + $timeout = 3600; + } + return Process::fromShellCommandline( $commandline, $cwd ? $cwd : $this->options['srcdir'], @@ -760,7 +763,8 @@ protected function doExecCommand($command, $outputHandler) if ($command['tty']) { - passthru(sprintf('%s; %s 2>&1', + passthru(sprintf( + '%s; %s 2>&1', "cd {$this->getLocalPath()}", $command['command'] ), $exit); @@ -771,7 +775,7 @@ protected function doExecCommand($command, $outputHandler) } else { $process = $this->getProcess( $command['command'], - $this->getLocalPath() + $this->getLocalPath(), ); $this->runProcess( @@ -784,7 +788,6 @@ protected function doExecCommand($command, $outputHandler) if (!$this->promptCommandFailureContinue($command, $exception, $process)) { exit(1); } - } } diff --git a/src/Command/TransferCommand.php b/src/Command/TransferCommand.php index 5244129..9e191bb 100644 --- a/src/Command/TransferCommand.php +++ b/src/Command/TransferCommand.php @@ -189,7 +189,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $resultHelper = $this->deploymentResultHelper; $beam->setResultStreamHandler( function ($changes) use ($resultHelper, $output) { - if (!empty($changes)) { + // show the calleee + $func = trim(debug_backtrace()[1]['function']); + + if (!empty($changes) && ($func == 'up' || $func == 'down')) { $result = $changes instanceof DeploymentResult ? $changes : new DeploymentResult($changes); @@ -201,6 +204,7 @@ function ($changes) use ($resultHelper, $output) { // Prompt the user with the affected files and a confirmation dialog if (!$input->getOption('no-prompt')) { + $output->writeln( $this->formatterHelper->formatSection( 'info', diff --git a/src/DeploymentProvider/Rsync.php b/src/DeploymentProvider/Rsync.php index 622d5bd..b5722b8 100644 --- a/src/DeploymentProvider/Rsync.php +++ b/src/DeploymentProvider/Rsync.php @@ -25,6 +25,11 @@ class Rsync extends Deployment implements DeploymentProvider, ResultStream */ protected $options = []; + /** + * @var int + */ + protected $timeout = 300; + /** * @var Closure */ @@ -652,8 +657,8 @@ protected function getOutputStreamHandler(Closure $callback = null, $silent = fa $buffer = substr($buffer, $lastNewLine); $result = $this->formatOutput($data); - $results[] = $result; + $results[] = $result; // Pass through, unless silenced if ($streamHandler) { $streamHandler($result); @@ -673,7 +678,7 @@ protected function getOutputStreamHandler(Closure $callback = null, $silent = fa */ public function getProcess($command): Process { - $process = Process::fromShellCommandline($command); + $process = Process::fromShellCommandline($command, null, null, null, $this->timeout); return $process; } diff --git a/src/Helper/DeploymentResultHelper.php b/src/Helper/DeploymentResultHelper.php index 1350534..3a6421d 100644 --- a/src/Helper/DeploymentResultHelper.php +++ b/src/Helper/DeploymentResultHelper.php @@ -51,6 +51,7 @@ public function outputChanges( ) { $totalNodes = count($deploymentResult->getNestedResults()); $output->getFormatter()->setStyle('count', new OutputFormatterStyle('cyan')); + foreach ($deploymentResult as $change) { if ($change['reason'] != ['time'] && (!$type || $change['update'] === $type)) { // If changes made to multiple servers, show total of modified servers for this line item @@ -67,7 +68,6 @@ public function outputChanges( ); $style = $change['update'] === 'deleted' ? 'error' : 'info'; $output->writeLn($this->formatterHelper->formatSection($change['update'], $message, $style)); - } } }