Last active
September 27, 2018 08:03
-
-
Save odinuv/e71c3827ce32b88c6a3874f0911341c1 to your computer and use it in GitHub Desktop.
Testing the untestable: Bad 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(); | |
$stmt = $pdo->prepare('SELECT …'); | |
while (true) { | |
try { | |
$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