You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exponential backoff really helps with unreliable APIs. A second failed attempt usually means the service is overloaded or there's a problem with network connectivity. In both cases it's best to pause for a longer period before retrying again.
It'd be great to have this option in Saloon. This is how I implement it in my apps. Happy to work on a PR if you're interested?
public function execute(int $id): array
{
$attempt = 0;
while ($attempt < $this->maxRetries + 1) {
try {
$response = Http::withToken($this->token)->get("{$this->baseUrl}/{$id}");
if ($response->successful()) {
return $response->json();
}
throw new RequestException($response);
} catch (RequestException $e) {
if ($attempt === $this->maxRetries) {
throw $e;
}
sleep($this->initialDelay * (2 ** $attempt));
}
$attempt++;
}
}
The text was updated successfully, but these errors were encountered:
Looking at your code, I don't think this would be even that big to implement into Saloon v3. Check out the new send() method in Saloon v3 - with the global retries everything is wrapped in a similar while, and we even have an interval - so I would say it would be as simple as adding a boolean to enable exponential back off?
Exponential backoff really helps with unreliable APIs. A second failed attempt usually means the service is overloaded or there's a problem with network connectivity. In both cases it's best to pause for a longer period before retrying again.
It'd be great to have this option in Saloon. This is how I implement it in my apps. Happy to work on a PR if you're interested?
The text was updated successfully, but these errors were encountered: