@@ -481,21 +481,36 @@ public function retrySession(Closure $userFunc, bool $idempotent = false, RetryP
481
481
482
482
}
483
483
484
- public function retryTransaction (Closure $ userFunc , bool $ idempotent = false , RetryParams $ params = null ){
484
+ public function retryTransaction (Closure $ userFunc , array | bool $ idempotentOrParams = false , RetryParams $ params = null ){
485
485
486
- return $ this ->retrySession (function (Session $ session ) use ($ userFunc ) {
486
+ if (is_array ($ idempotentOrParams )){
487
+ if (isset ($ idempotentOrParams ['idempotent ' ])){
488
+ $ idempotentFlag = $ idempotentOrParams ['idempotent ' ];
489
+ }
490
+ if (isset ($ idempotentOrParams ['retry_params ' ])){
491
+ $ params = $ idempotentOrParams ['retry_params ' ];
492
+ }
493
+ if (isset ($ idempotentOrParams ['callback_on_error ' ])){
494
+ $ callbackOnError = $ idempotentOrParams ['callback_on_error ' ];
495
+ }
496
+ } else {
497
+ $ idempotentFlag = $ idempotentOrParams ;
498
+ $ callbackOnError = function (\Exception $ exception ){};
499
+ }
500
+ return $ this ->retrySession (function (Session $ session ) use ($ callbackOnError , $ userFunc ) {
487
501
try {
488
502
$ session ->beginTransaction ();
489
503
$ result = $ userFunc ($ session );
490
504
$ session ->commitTransaction ();
491
505
return $ result ;
492
- } catch (Exception $ exception ){
506
+ } catch (\Exception $ exception ){
507
+ $ callbackOnError ($ exception );
493
508
try {
494
509
$ session ->rollbackTransaction ();
495
510
} catch (Exception $ e ){}
496
511
throw $ exception ;
497
512
}
498
- }, $ idempotent , $ params );
513
+ }, $ idempotentFlag , $ params );
499
514
500
515
}
501
516
0 commit comments