laravel retry failed transactions

Solutions on MaxInterview for laravel retry failed transactions by the best coders in the world

showing results for - "laravel retry failed transactions"
Cody
04 Feb 2019
1function tryFor10Seconds(Closure $closure) {
2
3  $runTheClosure = function ($closure) {
4    try {
5      DB::beginTransaction();
6
7      $closure();
8
9      DB::commit();
10
11      return true;
12    } catch (Exception $e) {
13      DB::rollBack();
14
15      // handle the exception if needed, log it or whatever
16
17      return false;
18    }
19  };
20
21  $start = time();
22  do {
23    $result = $runTheClosure($closure);
24  } while(!$result && (time() - $start <= 10));
25
26  return $result;
27}
28