From 786d74a090107ce44309b30cbb7f7b8dfb6f7610 Mon Sep 17 00:00:00 2001 From: warrickbayman Date: Mon, 24 Aug 2020 10:04:28 +0200 Subject: [PATCH] Increased the `Process` timeout to 3600 seconds. The `Deployer` class now has a `PROCESS_TIMEOUT` class constant set to 3600. Updated the `Deployer::executeTaskLocally` to update the timeout of the `Symfony\Component\Process` object. The signatore of the `Ssh::run()` method has been altered to accept a timeout integer as the second parameter. It defaults to 60. --- CHANGELOG.md | 4 ++++ bin/attache | 2 +- src/Deployer.php | 11 ++++++++--- src/Ssh.php | 14 ++++++++++---- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ffd4d..37d81d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.7.1] 24-08-2020 +### Changed +The timeout for all process has been substantially increased to 3600 seconds to cater for long running deployments. + ## [0.7.0] 12-08-2020 ### Changed * The configuration requires the `server` config setting has been changed from an array of objects to an object of servers keyed by their names. diff --git a/bin/attache b/bin/attache index f3e2ff4..e52a1b7 100755 --- a/bin/attache +++ b/bin/attache @@ -16,7 +16,7 @@ if (file_exists(__DIR__.'/../vendor/autoload.php')) { require __DIR__.'/../../../autoload.php'; } -$app = new \Symfony\Component\Console\Application('Attaché', '0.7.0'); +$app = new \Symfony\Component\Console\Application('Attaché', '0.7.1'); $app->add(new \TPG\Attache\Console\InitCommand()); $app->add(new \TPG\Attache\Console\ServersListCommand()); diff --git a/src/Deployer.php b/src/Deployer.php index 322e2fd..a6ef1f6 100644 --- a/src/Deployer.php +++ b/src/Deployer.php @@ -15,6 +15,11 @@ class Deployer */ protected const BUILD_COMMAND = ['yarn prod']; + /** + * Process timeout in seconds. + */ + protected const PROCESS_TIMEOUT = 3600; + /** * @var ConfigurationProvider */ @@ -64,7 +69,7 @@ public function __construct( * Deploy a release. * * @param string $releaseId - * @param bool $install + * @throws ProcessException */ public function deploy(string $releaseId): void { @@ -77,7 +82,6 @@ public function deploy(string $releaseId): void * Get the tasks to execute. * * @param string $releaseId - * @param bool $install * @return array */ public function getTasks(string $releaseId): array @@ -423,7 +427,7 @@ protected function executeTaskOnServer(Task $task): void { $code = (new Ssh($task))->tty()->run(function ($task, $output) { $this->getOutput()->writeln($output); - }); + }, self::PROCESS_TIMEOUT); if ($code !== 0) { $this->failProcess(); @@ -460,6 +464,7 @@ protected function failProcess(string $err = null): void protected function executeTaskLocally(Task $task): void { $process = Process::fromShellCommandline($task->getBashScript())->disableOutput(); + $process->setTimeout(self::PROCESS_TIMEOUT); if ($this->tty) { $process->setTty(Process::isTtySupported()); diff --git a/src/Ssh.php b/src/Ssh.php index 1cb8bc8..392f7e8 100644 --- a/src/Ssh.php +++ b/src/Ssh.php @@ -41,9 +41,10 @@ public function setTask(Task $task): void * Run the task. * * @param \Closure|null $callback + * @param int $timeout * @return int */ - public function run(\Closure $callback = null): int + public function run(\Closure $callback = null, int $timeout = 60): int { if (! $this->task) { throw new \RuntimeException('No task specified'); @@ -53,7 +54,7 @@ public function run(\Closure $callback = null): int throw new \RuntimeException('No server to connect to'); } - $process = $this->getProcess(); + $process = $this->getProcess($timeout); if ($this->tty) { $process->setTty(Process::isTtySupported()); @@ -87,14 +88,19 @@ public function tty(): self /** * Get a Process instance. * + * @param int $timeout * @return Process */ - protected function getProcess(): Process + protected function getProcess(int $timeout = 60): Process { - return Process::fromShellCommandline( + $process = Process::fromShellCommandline( 'ssh '.$this->getServerConnectionString().' ' .$this->script() )->setTimeout(null); + + $process->setTimeout($timeout); + + return $process; } /**