@@ -56,38 +56,36 @@ public function transaction(Closure $callback)
5656 while (!$ done and $ retry < self ::MaxRetries) {
5757 try {
5858 $ em = Registry::getManager ($ this ->manager_name );
59- $ con = $ em ->getConnection ();
60-
6159 if (!$ em ->isOpen ()) {
6260 Log::warning ("DoctrineTransactionService::transaction: entity manager is closed!, trying to re open... " );
6361 $ em = Registry::resetManager ($ this ->manager_name );
64- // new entity manager
65- $ con = $ em ->getConnection ();
6662 }
6763
68- $ con ->beginTransaction (); // suspend auto-commit
64+ $ em -> getConnection () ->beginTransaction (); // suspend auto-commit
6965 $ result = $ callback ($ this );
7066 $ em ->flush ();
71- $ con ->commit ();
67+ $ em -> getConnection () ->commit ();
7268 $ done = true ;
73- } catch (RetryableException $ ex ) {
74- Log::warning ("retrying ... " );
69+ }
70+ catch (RetryableException $ ex ) {
71+ Log::warning ($ ex );
72+ Log::warning ("DoctrineTransactionService::transaction Retrying ... " );
73+ $ em ->close ();
74+ $ em ->getConnection ()->rollBack ();
7575 Registry::resetManager ($ this ->manager_name );
76- $ con ->rollBack ();
7776 Log::warning ($ ex );
7877 $ retry ++;
7978 if ($ retry === self ::MaxRetries) {
80- $ em ->close ();
81- $ con ->rollBack ();
82- Registry::resetManager ($ this ->manager_name );
79+ Log::info (sprintf ("DoctrineTransactionService::transaction Max Retry Reached %s " , $ retry ));
8380 throw $ ex ;
8481 }
85- } catch (Exception $ ex ) {
86- Log::warning ("rolling back transaction " );
82+ }
83+ catch (Exception $ ex ) {
84+ Log::warning ($ ex );
8785 $ em ->close ();
88- $ con ->rollBack ();
86+ Log::warning ("DoctrineTransactionService::transaction rolling back TX " );
87+ $ em ->getConnection ()->rollBack ();
8988 Registry::resetManager ($ this ->manager_name );
90- Log::warning ($ ex );
9189 throw $ ex ;
9290 }
9391 }
0 commit comments