Skip to content

Commit

Permalink
Merge pull request #302 from zecipriano/build-timeout
Browse files Browse the repository at this point in the history
Add a timeout option to the build command
  • Loading branch information
nunomaduro committed Dec 10, 2018
2 parents f8a69d2 + f7ba85c commit f363b03
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class BuildCommand extends Command
/**
* {@inheritdoc}
*/
protected $signature = 'app:build {name? : The build name}';
protected $signature = 'app:build {name? : The build name} {--timeout=300 : The timeout in seconds or 0 to disable}';

/**
* {@inheritdoc}
Expand Down Expand Up @@ -94,7 +94,10 @@ private function compile(string $name): BuildCommand

$process = new Process(
'./box compile'.' --working-dir='.base_path().' --config='.base_path('box.json'),
dirname(dirname(__DIR__)).'/bin'
dirname(dirname(__DIR__)).'/bin',
null,
null,
$this->getTimeout()
);

$section = tap($this->originalOutput->section())->write('');
Expand Down Expand Up @@ -161,6 +164,24 @@ private function getBinary(): string
return str_replace(["'", '"'], '', Artisan::artisanBinary());
}

/**
* Returns a valid timeout value. Non positive values are converted to null,
* meaning no timeout.
*
* @return float|null
* @throws \InvalidArgumentException
*/
private function getTimeout(): ?float
{
if (! is_numeric($this->option('timeout'))) {
throw new \InvalidArgumentException('The timeout value must be a number.');
}

$timeout = (float) $this->option('timeout');

return $timeout > 0 ? $timeout : null;
}

/**
* Makes sure that the `clear` is performed even
* if the command fails.
Expand Down

0 comments on commit f363b03

Please sign in to comment.