Skip to content

Commit 2c4bf59

Browse files
committed
changed retry behavior to better handle 502s, hopefully
1 parent c6bdb47 commit 2c4bf59

File tree

1 file changed

+2
-46
lines changed

1 file changed

+2
-46
lines changed

src/Services/FileMakerConnection.php

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77
use GearboxSolutions\EloquentFileMaker\Database\Query\Grammars\FMGrammar;
88
use GearboxSolutions\EloquentFileMaker\Database\Schema\FMBuilder;
99
use GearboxSolutions\EloquentFileMaker\Exceptions\FileMakerDataApiException;
10-
use GuzzleHttp\Exception\TransferException;
11-
use GuzzleHttp\Middleware;
1210
use Illuminate\Database\Connection;
1311
use Illuminate\Http\Client\PendingRequest;
1412
use Illuminate\Http\UploadedFile;
1513
use Illuminate\Support\Arr;
1614
use Illuminate\Support\Collection;
1715
use Illuminate\Support\Facades\Cache;
1816
use Illuminate\Support\Facades\Http;
19-
use Psr\Http\Message\RequestInterface;
20-
use Psr\Http\Message\ResponseInterface;
2117
use Symfony\Component\HttpFoundation\File\File;
2218

2319
class FileMakerConnection extends Connection
@@ -114,7 +110,7 @@ protected function fetchNewSessionToken()
114110
];
115111

116112
// perform the login
117-
$response = Http::withBasicAuth($this->config['username'], $this->config['password'])
113+
$response = Http::retry($this->retries, 100)->withBasicAuth($this->config['username'], $this->config['password'])
118114
->post($url, $postBody);
119115

120116
// Check for errors
@@ -683,11 +679,9 @@ protected function prepareRequestForSending($request)
683679
if ($request instanceof PendingRequest) {
684680
$request->withToken($this->sessionToken);
685681
} else {
686-
$request = Http::withToken($this->sessionToken);
682+
$request = Http::retry($this->retries, 100)->withoutVerifying()->withToken($this->sessionToken);
687683
}
688684

689-
$request->withMiddleware($this->retryMiddleware());
690-
691685
return $request;
692686
}
693687

@@ -732,44 +726,6 @@ public function setRetries($retries)
732726
return $this;
733727
}
734728

735-
protected function retryMiddleware()
736-
{
737-
return Middleware::retry(function (
738-
$retries,
739-
RequestInterface $request,
740-
?ResponseInterface $response = null,
741-
?TransferException $exception = null
742-
) {
743-
// Limit the number of retries to 5
744-
if ($retries >= $this->retries) {
745-
return false;
746-
}
747-
748-
$should_retry = false;
749-
$log_message = null;
750-
751-
// Retry connection exceptions
752-
if ($exception instanceof TransferException) {
753-
$should_retry = true;
754-
$log_message = 'Connection Error: ' . $exception->getMessage();
755-
}
756-
757-
if ($log_message) {
758-
error_log($log_message, 0);
759-
}
760-
761-
if ($should_retry) {
762-
if ($retries > 0) {
763-
error_log('Retry ' . $retries . '', 0);
764-
}
765-
}
766-
767-
return $should_retry;
768-
}, function () {
769-
return 0;
770-
});
771-
}
772-
773729
protected function getDefaultQueryGrammar()
774730
{
775731
return new FMGrammar();

0 commit comments

Comments
 (0)