Laravelのソースコードを呼んでいたら良さげなリトライ実装がされていたのでメモ
function retry($times, callable $callback, $sleep = 0)
{
$attempts = 0;
$times--;
beginning:
$attempts++;
try {
return $callback($attempts);
} catch (Exception $e) {
if (! $times) {
throw $e;
}
$times--;
if ($sleep) {
usleep($sleep * 1000);
}
goto beginning;
}
}