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

Wait for reused brancher when it's still being created #127

Closed
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
4 changes: 2 additions & 2 deletions src/Brancher/BrancherHypernodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
try {
$flows = $this->hypernodeClient->logbook->getList($brancherHypernode);
$relevantFlows = array_filter($flows, fn(Flow $flow) => $flow->name === 'ensure_app');
$failedFlows = array_filter($flows, fn(Flow $flow) => $flow->isReverted());
$completedFlows = array_filter($flows, fn(Flow $flow) => $flow->isComplete());
$failedFlows = array_filter($relevantFlows, fn(Flow $flow) => $flow->isReverted());
$completedFlows = array_filter($relevantFlows, fn(Flow $flow) => $flow->isComplete());

if (count($failedFlows) === count($relevantFlows)) {
throw new CreateBrancherHypernodeFailedException();
Expand Down
19 changes: 11 additions & 8 deletions src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,25 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche
$data['labels'] = $labels;
if ($reuseBrancher && $brancherApp = $this->brancherHypernodeManager->reuseExistingBrancherHypernode($parentApp, $labels)) {
$this->log->info(sprintf('Found existing brancher Hypernode, name is %s.', $brancherApp));
$server->setHostname(sprintf("%s.hypernode.io", $brancherApp));
} else {
$brancherApp = $this->brancherHypernodeManager->createForHypernode($parentApp, $data);
$this->log->info(sprintf('Successfully requested brancher Hypernode, name is %s.', $brancherApp));
$server->setHostname(sprintf("%s.hypernode.io", $brancherApp));
$this->brancherHypernodesRegistered[] = $brancherApp;
}

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

throw $e;
}

$server->setHostname(sprintf("%s.hypernode.io", $brancherApp));
}
}

Expand Down
Loading