diff --git a/src/Commands/Env/WakeCommand.php b/src/Commands/Env/WakeCommand.php index 083d86e90..52512d865 100644 --- a/src/Commands/Env/WakeCommand.php +++ b/src/Commands/Env/WakeCommand.php @@ -26,15 +26,40 @@ class WakeCommand extends TerminusCommand implements SiteAwareInterface * * @param string $site_env Site & environment in the format `site-name.env` * + * @option int $retry Number of times to retry if the environment is not awake + * @option int $delay Number of seconds to wait between retries + * * @throws TerminusException * * @usage . Wakes 's environment by pinging it. */ - public function wake($site_env) + public function wake($site_env, $options = [ + 'retry' => 3, + 'delay' => 3, + ]) { + $attempt = 1; $this->requireSiteIsNotFrozen($site_env); $env = $this->getEnv($site_env); - $wakeStatus = $env->wake(); + + while ($attempt <= $options['retry']) { + $wakeStatus = $env->wake(); + if (empty($wakeStatus['success'])) { + $this->log()->notice('{target} is not awake (attempt {attempt}/{max})...', [ + 'target' => $site_env, + 'attempt' => $attempt, + 'max' => $options['retry'], + ]); + // If there is any attempt remaining, sleep for the delay period. + if ($attempt <= $options['retry'] - 1) { + $this->log()->notice('Sleeping for {delay} seconds...', ['delay' => $options['delay']]); + sleep($options['delay']); + } + $attempt++; + continue; + } + break; + } // @TODO: Move the exceptions up the chain to the `wake` function. (One env is ported over). if (empty($wakeStatus['success'])) {