feat: improved contingents api performance with db backed snapshots
This commit is contained in:
@@ -11,6 +11,12 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
abstract class AbstractApiClient
|
||||
{
|
||||
/** Maximum time to wait between two bytes of the response. */
|
||||
private const int IDLE_TIMEOUT_SECONDS = 10;
|
||||
|
||||
/** Hard ceiling on a single request, including a slow-but-alive upstream. */
|
||||
private const int MAX_DURATION_SECONDS = 30;
|
||||
|
||||
public function __construct(
|
||||
protected readonly HttpClientInterface $httpClient,
|
||||
protected readonly LoggerInterface $logger,
|
||||
@@ -21,6 +27,7 @@ abstract class AbstractApiClient
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $query
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function request(string $path, array $query = []): array
|
||||
@@ -33,6 +40,11 @@ abstract class AbstractApiClient
|
||||
'X-API-KEY' => $this->apiKey,
|
||||
],
|
||||
'query' => $query,
|
||||
// Without these a stalled upstream hangs the caller indefinitely. That matters
|
||||
// most for the scheduled contingent sync, which holds a lock: one hung run would
|
||||
// block every subsequent one and silently let the snapshot rot.
|
||||
'timeout' => self::IDLE_TIMEOUT_SECONDS,
|
||||
'max_duration' => self::MAX_DURATION_SECONDS,
|
||||
]);
|
||||
|
||||
return $response->toArray();
|
||||
|
||||
Reference in New Issue
Block a user