Skip to content

Instantly share code, notes, and snippets.

@odinuv
Last active September 27, 2018 08:03
Show Gist options
  • Save odinuv/e71c3827ce32b88c6a3874f0911341c1 to your computer and use it in GitHub Desktop.
Save odinuv/e71c3827ce32b88c6a3874f0911341c1 to your computer and use it in GitHub Desktop.
Testing the untestable: Bad retry code
<?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