Skip to content

Commit

Permalink
health checks: limit retries for typesense
Browse files Browse the repository at this point in the history
By default we retry for 4095, because in a background job
we don't care, but for health checks we want to fail quicker
if the backend is down.
  • Loading branch information
lazka committed Aug 26, 2024
1 parent 1cf5c1e commit adcf2bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/TypesenseClient/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(string $baseUrl, string $apikey)
$this->logger = new NullLogger();
}

public function getClient(): Client
public function getClient(int $numRetries = self::TYPESENSE_CLIENT_RETRY_COUNT): Client
{
$parsedUrl = parse_url($this->baseUrl);
if ($parsedUrl === false) {
Expand All @@ -61,7 +61,7 @@ public function getClient(): Client
$symfonyClient = new TraceableHttpClient(HttpClient::create());
$symfonyClient->setLogger($this->logger);
$symfonyClient = new RetryableHttpClient(
$symfonyClient, null, self::TYPESENSE_CLIENT_RETRY_COUNT,
$symfonyClient, null, $numRetries,
$this->logger);

return new Client(
Expand Down
3 changes: 2 additions & 1 deletion src/TypesenseClient/SearchIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public function setLogger(LoggerInterface $logger): void

public function checkConnection(): void
{
$client = $this->connection->getClient();
// Limit retries, so we fail more quickly
$client = $this->connection->getClient(3);
$client->getHealth()->retrieve();
$client->getMultiSearch()->perform(['searches' => [['q' => 'healthcheck']]]);
}
Expand Down

0 comments on commit adcf2bd

Please sign in to comment.