Skip to content

Commit bfd7361

Browse files
committed
Added retryTransaction function
1 parent 387762f commit bfd7361

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Table.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,23 @@ public function retrySession(Closure $userFunc, bool $idempotent = false, RetryP
461461

462462
}
463463

464+
public function retryTransaction(Closure $userFunc, bool $idempotent = false, RetryParams $params = null){
465+
466+
return $this->retry->withParams($params)->retry(function () use ($userFunc){
467+
$sessionId = null;
468+
try{
469+
$session = $this->session();
470+
$sessionId = $session->id();
471+
$session->beginTransaction();
472+
$result = $userFunc($session);
473+
$session->commitTransaction();
474+
return $result;
475+
}catch (BadSessionException $bse){
476+
$this->dropSession($sessionId);
477+
throw $bse;
478+
}
479+
}, $idempotent);
480+
481+
}
482+
464483
}

0 commit comments

Comments
 (0)