Skip to content

Commit

Permalink
Merge pull request #132 from ByteInternet/feature/reuse-brancher
Browse files Browse the repository at this point in the history
Wait for reused branche when it's still being created
  • Loading branch information
tdgroot authored Jan 9, 2025
2 parents 27a71ae + 9e1624e commit fe68f78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
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
18 changes: 10 additions & 8 deletions src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,24 @@ 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 has become 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

0 comments on commit fe68f78

Please sign in to comment.