Skip to content

Commit fe68f78

Browse files
authored
Merge pull request #132 from ByteInternet/feature/reuse-brancher
Wait for reused branche when it's still being created
2 parents 27a71ae + 9e1624e commit fe68f78

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/Brancher/BrancherHypernodeManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
129129
try {
130130
$flows = $this->hypernodeClient->logbook->getList($brancherHypernode);
131131
$relevantFlows = array_filter($flows, fn(Flow $flow) => $flow->name === 'ensure_app');
132-
$failedFlows = array_filter($flows, fn(Flow $flow) => $flow->isReverted());
133-
$completedFlows = array_filter($flows, fn(Flow $flow) => $flow->isComplete());
132+
$failedFlows = array_filter($relevantFlows, fn(Flow $flow) => $flow->isReverted());
133+
$completedFlows = array_filter($relevantFlows, fn(Flow $flow) => $flow->isComplete());
134134

135135
if (count($failedFlows) === count($relevantFlows)) {
136136
throw new CreateBrancherHypernodeFailedException();

src/DeployRunner.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,22 +291,24 @@ private function maybeConfigureBrancherServer(Server $server, bool $reuseBranche
291291
$data['labels'] = $labels;
292292
if ($reuseBrancher && $brancherApp = $this->brancherHypernodeManager->reuseExistingBrancherHypernode($parentApp, $labels)) {
293293
$this->log->info(sprintf('Found existing brancher Hypernode, name is %s.', $brancherApp));
294-
$server->setHostname(sprintf("%s.hypernode.io", $brancherApp));
295294
} else {
296295
$brancherApp = $this->brancherHypernodeManager->createForHypernode($parentApp, $data);
297296
$this->log->info(sprintf('Successfully requested brancher Hypernode, name is %s.', $brancherApp));
298-
$server->setHostname(sprintf("%s.hypernode.io", $brancherApp));
299297
$this->brancherHypernodesRegistered[] = $brancherApp;
298+
}
300299

301-
try {
302-
$this->log->info('Waiting for brancher Hypernode to become available...');
303-
$this->brancherHypernodeManager->waitForAvailability($brancherApp);
304-
$this->log->info('Brancher Hypernode has become available!');
305-
} catch (CreateBrancherHypernodeFailedException | TimeoutException $e) {
300+
try {
301+
$this->log->info('Waiting for brancher Hypernode to become available...');
302+
$this->brancherHypernodeManager->waitForAvailability($brancherApp);
303+
$this->log->info('Brancher Hypernode has become available!');
304+
} catch (CreateBrancherHypernodeFailedException | TimeoutException $e) {
305+
if (in_array($brancherApp, $this->brancherHypernodesRegistered)) {
306306
$this->brancherHypernodeManager->cancel($brancherApp);
307-
throw $e;
308307
}
308+
309+
throw $e;
309310
}
311+
$server->setHostname(sprintf("%s.hypernode.io", $brancherApp));
310312
}
311313
}
312314

0 commit comments

Comments
 (0)