Skip to content

Instantly share code, notes, and snippets.

@odinuv
Created September 27, 2018 15:09
Show Gist options
  • Save odinuv/b1da41d9aecb5825314e6bb5009623c3 to your computer and use it in GitHub Desktop.
Save odinuv/b1da41d9aecb5825314e6bb5009623c3 to your computer and use it in GitHub Desktop.
Testing the untestable: Fixed retry code
<?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