}
- public static function retryOnError(callable $callback, $attempts = 3)
+ /**
+ * @param callable $callback
+ * @param $attempts int
+ * @param $pauseBetweenAttemps float
+ * @return mixed
+ */
+ public static function retryOnError(callable $callback, $attempts = 3, $pauseBetweenAttemps = 0)
{
try {
return call_user_func($callback);
} catch (\Exception $e) {
if ($attemps > 0) {
+ if ($pauseBetweenAttemps > 0) {
+ usleep($pauseBetweenAttemps / 1000000);
+ }
return self::retryOnError($callback, $attempts - 1);
}
throw $e;