Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"doctrine/annotations": "^1.6",
"guzzlehttp/guzzle": "^7.5",
"hypernode/api-client": "^0.5",
"hypernode/deploy-configuration": "^3.5",
"hypernode/deploy-configuration": "dev-more-robust-dns-check as 3.5.99",
"php-di/php-di": "^7.0",
"psr/log": "^1.0",
"symfony/console": "^5.4",
Expand Down Expand Up @@ -55,6 +55,10 @@
"deployer-fork": {
"type": "vcs",
"url": "https://github.com/ByteInternet/deployer"
},
"deploy-configuration": {
"type": "vcs",
"url": "https://github.com/ByteInternet/hypernode-deploy-configuration"
}
}
}
43 changes: 37 additions & 6 deletions src/Brancher/BrancherHypernodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,20 @@ public function createForHypernode(string $hypernode, array $data = []): string
*
* @param string $brancherHypernode Name of the brancher Hypernode
* @param int $timeout Maximum time to wait for availability
* @param int $reachabilityCheckCount Number of consecutive successful checks required
* @param int $reachabilityCheckInterval Seconds between reachability checks
* @return void
* @throws CreateBrancherHypernodeFailedException
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
* @throws TimeoutException
*/
public function waitForAvailability(string $brancherHypernode, int $timeout = 1500): void
{
public function waitForAvailability(
string $brancherHypernode,
int $timeout = 1500,
int $reachabilityCheckCount = 6,
int $reachabilityCheckInterval = 10
): void {
$latest = microtime(true);
$timeElapsed = 0;
$resolved = false;
Expand Down Expand Up @@ -175,7 +181,7 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
);
}

$resolved = false;
$consecutiveSuccesses = 0;
while ($timeElapsed < $timeout) {
$now = microtime(true);
$timeElapsed += $now - $latest;
Expand All @@ -184,12 +190,37 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
$connection = @fsockopen(sprintf("%s.hypernode.io", $brancherHypernode), 22);
if ($connection) {
fclose($connection);
$resolved = true;
break;
$consecutiveSuccesses++;
$this->log->info(
sprintf(
'Brancher Hypernode %s reachability check %d/%d succeeded.',
$brancherHypernode,
$consecutiveSuccesses,
$reachabilityCheckCount
)
);

if ($consecutiveSuccesses >= $reachabilityCheckCount) {
break;
}
sleep($reachabilityCheckInterval);
} else {
if ($consecutiveSuccesses > 0) {
$this->log->info(
sprintf(
'Brancher Hypernode %s reachability check failed, resetting counter (was at %d/%d).',
$brancherHypernode,
$consecutiveSuccesses,
$reachabilityCheckCount
)
);
}
$consecutiveSuccesses = 0;
sleep($reachabilityCheckInterval);
}
}

if (!$resolved) {
if ($consecutiveSuccesses < $reachabilityCheckCount) {
throw new TimeoutException(
sprintf('Timed out waiting for brancher Hypernode %s to become reachable', $brancherHypernode)
);
Expand Down
9 changes: 8 additions & 1 deletion src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche
if ($isBrancher && $parentApp) {
$settings = $serverOptions[Server::OPTION_HN_BRANCHER_SETTINGS] ?? [];
$labels = $serverOptions[Server::OPTION_HN_BRANCHER_LABELS] ?? [];
$reachabilityCheckCount = $serverOptions[Server::OPTION_HN_BRANCHER_REACHABILITY_CHECK_COUNT] ?? 6;
$reachabilityCheckInterval = $serverOptions[Server::OPTION_HN_BRANCHER_REACHABILITY_CHECK_INTERVAL] ?? 10;

$this->log->info(sprintf('Creating an brancher Hypernode based on %s.', $parentApp));
if ($settings) {
Expand All @@ -299,7 +301,12 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche

try {
$this->log->info('Waiting for brancher Hypernode to become available...');
$this->brancherHypernodeManager->waitForAvailability($brancherApp);
$this->brancherHypernodeManager->waitForAvailability(
$brancherApp,
1500,
$reachabilityCheckCount,
$reachabilityCheckInterval
);
$this->log->info('Brancher Hypernode has become available!');
} catch (CreateBrancherHypernodeFailedException | TimeoutException $e) {
if (in_array($brancherApp, $this->brancherHypernodesRegistered)) {
Expand Down
Loading