Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel retry failed transactions

function tryFor10Seconds(Closure $closure) {

  $runTheClosure = function ($closure) {
    try {
      DB::beginTransaction();

      $closure();

      DB::commit();

      return true;
    } catch (Exception $e) {
      DB::rollBack();

      // handle the exception if needed, log it or whatever

      return false;
    }
  };

  $start = time();
  do {
    $result = $runTheClosure($closure);
  } while(!$result && (time() - $start <= 10));

  return $result;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #laravel #retry #failed #transactions
ADD COMMENT
Topic
Name
6+1 =