Skip to content

Commit 1090427

Browse files
author
Илья
committed
Added recreate client on YDB_UNAVAILABLE
1 parent 097759e commit 1090427

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Traits/RequestTrait.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,19 @@ protected function processResponse($service, $method, $response, $resultClass)
236236
$this->resetLastRequest();
237237

238238
return $result;
239+
} elseif ($statusCode == StatusCode::UNAVAILABLE){
240+
if ($this->ydb->needDiscovery()){
241+
try{
242+
$this->ydb->discover();
243+
}catch (\Exception $e){}
244+
}
245+
$endpoint = $this->ydb->endpoint();
246+
if ($this->ydb->needDiscovery() && count($this->ydb->cluster()->all()) > 0){
247+
$endpoint = $this->ydb->cluster()->all()[array_rand($this->ydb->cluster()->all())]->endpoint();
248+
}
249+
$this->client = new $this->client($endpoint,[
250+
'credentials' => $this->ydb->iam()->getCredentials()
251+
]);
239252
}
240253
$statusName = StatusCode::name($statusCode);
241254

0 commit comments

Comments
 (0)