Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGS-6554] Add retry and delay options. #2498

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/Commands/Env/WakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
Loading