Skip to content

Commit

Permalink
improve retry logic for downloadFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
dforsber committed Aug 19, 2017
1 parent f676378 commit 5bdff6a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions wscli-php-sdk/src/WsCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,18 @@ private function handleFiles($api, $cmd)
}
$local_dir = str_replace("//", "/", $local_dir . "/");
$this->log->debug("Local (sync) dir: " . $local_dir);
$resp = $this->__call($cmd, [$api]);
$retry_count = $this->retries;
do {
if ($retry_count < $this->retries) {
$this->log->debug("retry " . $retry_count . "...");
echo "Trying again: ";
}
$resp = $this->__call($cmd, [$api]);
if (!array_key_exists('response_code', $resp) || $resp['response_code'] != "00") {
echo " FAILED" . PHP_EOL;
$retry_count--;
}
} while ((!array_key_exists('response_code', $resp) || $resp['response_code'] != "00") && $retry_count > 0);
if ($resp['response_code'] == "00") {
foreach ($resp['file_descriptors'] as $desc) {
if ($fileref != "" && $fileref != $desc['file_reference']) {
Expand Down Expand Up @@ -401,7 +412,7 @@ private function handleFiles($api, $cmd)
echo " FAILED" . PHP_EOL;
$retry_count--;
}
} while ($download_resp['response_code'] != "00" && $retry_count > 0);
} while ((!array_key_exists('response_code', $download_resp) || $download_resp['response_code'] != "00") && $retry_count > 0);
if ($download_resp['response_code'] != "00" && $retry_count <= 0) {
$this->log->error("Failed to download file " . $local_filename);
$this->log->error(print_r($download_resp, true));
Expand Down

0 comments on commit 5bdff6a

Please sign in to comment.