Skip to content

Commit

Permalink
ONCALL-398 Remove while loop for analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayaAvocado committed May 18, 2022
1 parent 60732f6 commit 7fc9b0c
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/Rox/Core/XPack/Analytics/AnalyticsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,13 @@ private function _flushBatch(array $messages)
{
$batch = $this->_createBatch($messages);
$url = Environment::getAnalyticsPath() . "/impression/" . $this->_deviceProperties->getRolloutKey();
$backoff = 100; // Set initial waiting time to 100ms
while ($backoff < $this->_maximum_backoff_duration) {
$response = $this->_httpClient->postJson($url, $batch);
$statusCode = $response->getStatusCode();
if (200 == $statusCode) {
return true;
}
$this->_log->error("Failed to post data to ${url}: HTTP response code ${statusCode} ({$response->getContent()->readAsString()})");
if (($statusCode >= 500 && $statusCode <= 600) || 429 == $statusCode) {
// If status code is greater than 500 and less than 600, it indicates server error
// Error code 429 indicates rate limited.
// Retry uploading in these cases.
usleep($backoff * 1000);
$backoff *= 2;
} elseif ($statusCode >= 400) {
return false;
}
$response = $this->_httpClient->postJson($url, $batch);
$statusCode = $response->getStatusCode();
if (200 == $statusCode) {
return true;
}
$this->_log->error("Failed to post data to ${url}: HTTP response code ${statusCode} ({$response->getContent()->readAsString()})");

return false;
}

Expand Down

0 comments on commit 7fc9b0c

Please sign in to comment.