Skip to content

Commit

Permalink
fix: increase process timeout, stop dumping multiple output lines in …
Browse files Browse the repository at this point in the history
…stream results
  • Loading branch information
wilr committed Jun 9, 2024
1 parent 539b54f commit 6feaac1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/Beam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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."
);
}

}
}

Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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);
Expand All @@ -771,7 +775,7 @@ protected function doExecCommand($command, $outputHandler)
} else {
$process = $this->getProcess(
$command['command'],
$this->getLocalPath()
$this->getLocalPath(),
);

$this->runProcess(
Expand All @@ -784,7 +788,6 @@ protected function doExecCommand($command, $outputHandler)
if (!$this->promptCommandFailureContinue($command, $exception, $process)) {
exit(1);
}

}
}

Expand Down
6 changes: 5 additions & 1 deletion src/Command/TransferCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand Down
9 changes: 7 additions & 2 deletions src/DeploymentProvider/Rsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Rsync extends Deployment implements DeploymentProvider, ResultStream
*/
protected $options = [];

/**
* @var int
*/
protected $timeout = 300;

/**
* @var Closure
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/DeploymentResultHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,7 +68,6 @@ public function outputChanges(
);
$style = $change['update'] === 'deleted' ? 'error' : 'info';
$output->writeLn($this->formatterHelper->formatSection($change['update'], $message, $style));

}
}
}
Expand Down

0 comments on commit 6feaac1

Please sign in to comment.