Skip to content

Commit

Permalink
[BUGS-6554] Add retry and delay options. (#2498)
Browse files Browse the repository at this point in the history
* Initial attempt to add retry and delay options.

* Improve messaging and other improvements.
kporras07 authored Sep 21, 2023
1 parent be0691c commit d9128fc
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/Commands/Env/WakeCommand.php
Original file line number Diff line number Diff line change
@@ -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 <site>.<env> Wakes <site>'s <env> 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'])) {

0 comments on commit d9128fc

Please sign in to comment.