Skip to content
Draft
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/Helpers/Traits/WaitForWakeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ trait WaitForWakeTrait
public function waitForWake(Environment $env, LoggerInterface $logger)
{
$waits = 0;
$max_waits = $this->getConfig()->get('max_waits', 25);
$logger->debug('max_waits: {max_waits}', ['max_waits' => $max_waits]);
do {
$logger->debug('wait #{waits}', ['waits' => $waits+1]);
$woke = $env->wake();
if (($woke['success'] ?? false) === true) {
break;
}
// if success is empty, then the site is still waking up.
// Allow user to set the number of retries if the site is still waking up.
// Default should be 25 times, once per second.
if ($waits > $this->getConfig()->get("wait_for_wake_repeat", 25)) {
if ($waits > $max_waits) {
$this->log()->error('{target} could not be reached, domain returned {status_code}.', [
'status_code' => $woke['response']['status_code'],
]);
Expand Down
21 changes: 21 additions & 0 deletions src/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,15 @@ public function sftpConnectionInfo()
*/
public function wake(int $maxRetries = 3, int $delay = 5): array
{
$this->logger->debug(
'Waking {site} environment {env} with {maxRetries} retries and {delay} seconds delay',
[
'site' => $this->getSite()->getName(),
'env' => $this->id,
'maxRetries' => $maxRetries,
'delay' => $delay,
]
);
$domains = array_filter(
$this->getDomains()->all(),
function ($domain) {
Expand All @@ -1022,12 +1031,24 @@ function ($domain) {
$lastError = null;

while ($attempt < $maxRetries && !$success) {
$this->logger->debug(
'Attempt {attempt} to wake {site} environment {env}',
[
'attempt' => $attempt + 1,
'site' => $this->getSite()->getName(),
'env' => $this->id,
]
);
$lastError = null;
$attempt++;
try {
$response = $this->request()->request(
"https://{$domain->id}/pantheon_healthcheck"
);
$this->logger->debug(
'Response: {response}',
['response' => $response]
);
$success = ($response['status_code'] === 200);
if ($success) {
return [
Expand Down
17 changes: 16 additions & 1 deletion src/Models/TerminusModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Pantheon\Terminus\Request\RequestAwareInterface;
use Pantheon\Terminus\Request\RequestAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;

/**
* Class TerminusModel
Expand All @@ -15,10 +18,12 @@
*/
abstract class TerminusModel implements
ConfigAwareInterface,
RequestAwareInterface
RequestAwareInterface,
LoggerAwareInterface
{
use ConfigAwareTrait;
use RequestAwareTrait;
use LoggerAwareTrait;

public const PRETTY_NAME = 'terminus model';

Expand Down Expand Up @@ -68,6 +73,16 @@ public function __construct($attributes = null, array $options = [])
}
}

/**
* Returns a logger object for use
*
* @return LoggerInterface
*/
protected function log()
{
return $this->logger;
}

/**
* Fetches this object from Pantheon
*
Expand Down
Loading