Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
Increased the Process timeout to 3600 seconds.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
warrickbayman committed Aug 24, 2020
1 parent f69190d commit 786d74a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bin/attache
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 8 additions & 3 deletions src/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class Deployer
*/
protected const BUILD_COMMAND = ['yarn prod'];

/**
* Process timeout in seconds.
*/
protected const PROCESS_TIMEOUT = 3600;

/**
* @var ConfigurationProvider
*/
Expand Down Expand Up @@ -64,7 +69,7 @@ public function __construct(
* Deploy a release.
*
* @param string $releaseId
* @param bool $install
* @throws ProcessException
*/
public function deploy(string $releaseId): void
{
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
14 changes: 10 additions & 4 deletions src/Ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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());
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 786d74a

Please sign in to comment.