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
Copy file name to clipboardExpand all lines: app/Services/Utils/DoctrineTransactionService.php
+55-23Lines changed: 55 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -11,12 +11,16 @@
11
11
* See the License for the specific language governing permissions and
12
12
* limitations under the License.
13
13
**/
14
+
15
+
useDoctrine\DBAL\Exception\ConnectionLost;
16
+
useDoctrine\DBAL\TransactionIsolationLevel;
14
17
useIlluminate\Support\Facades\Log;
15
18
useClosure;
16
19
useLaravelDoctrine\ORM\Facades\Registry;
17
20
useDoctrine\DBAL\Exception\RetryableException;
18
21
useException;
19
22
useUtils\Db\ITransactionService;
23
+
20
24
/**
21
25
* Class DoctrineTransactionService
22
26
* @package App\Services\Utils
@@ -40,14 +44,33 @@ public function __construct($manager_name)
40
44
}
41
45
42
46
/**
43
-
* Execute a Closure within a transaction.
44
-
*
45
-
* @param Closure $callback
46
-
* @return mixed
47
-
*
48
-
* @throws \Exception
47
+
* @param Exception $e
48
+
* @return bool
49
+
*/
50
+
publicfunctionshouldReconnect(\Exception$e):bool
51
+
{
52
+
if($einstanceof RetryableException) returntrue;
53
+
if($einstanceof ConnectionLost) returntrue;
54
+
if($einstanceof \PDOException){
55
+
switch(intval($e->getCode())){
56
+
case2006:
57
+
Log::warning("DoctrineTransactionService::shouldReconnect: MySQL server has gone away!");
58
+
returntrue;
59
+
case2002:
60
+
Log::warning("DoctrineTransactionService::shouldReconnect: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known!");
0 commit comments