Created
September 27, 2018 15:09
-
-
Save odinuv/b1da41d9aecb5825314e6bb5009623c3 to your computer and use it in GitHub Desktop.
Testing the untestable: Fixed retry code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pdo = $this->connect(); | |
while (true) { | |
try { | |
$stmt = $pdo->prepare('SELECT …'); // <- must be inside the loop | |
$stmt->execute(); | |
while ($row = $stmt->fetch()) { | |
write_row_to_csv($row); | |
} | |
break; //success | |
} catch (\Throwable $e) { | |
$retries++; | |
if ($retries > 10) { | |
throw new \Exception('failed to retry'); | |
} | |
sleep(10); | |
$pdo = $this->connect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment