Add support for retry and wait to Galaxy API and downloader API

This commit is contained in:
Sude 2018-12-22 11:35:17 +02:00
parent df628b2a59
commit 9bd416e3b0
2 changed files with 26 additions and 6 deletions

View File

@ -242,9 +242,19 @@ std::string API::getResponse(const std::string& url)
curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, writeMemoryCallback); curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, writeMemoryCallback);
curl_easy_setopt(curlhandle, CURLOPT_WRITEDATA, &memory); curl_easy_setopt(curlhandle, CURLOPT_WRITEDATA, &memory);
CURLcode result = curl_easy_perform(curlhandle);
std::string response = memory.str(); int retries = 0;
memory.str(std::string()); CURLcode result;
std::string response;
do
{
if (Globals::globalConfig.iWait > 0)
usleep(Globals::globalConfig.iWait); // Delay the request by specified time
result = curl_easy_perform(curlhandle);
response = memory.str();
memory.str(std::string());
}
while ((result != CURLE_OK) && response.empty() && (retries++ < Globals::globalConfig.iRetries));
if (result == CURLE_HTTP_RETURNED_ERROR) if (result == CURLE_HTTP_RETURNED_ERROR)
{ {

View File

@ -117,9 +117,19 @@ std::string galaxyAPI::getResponse(const std::string& url, const bool& zlib_deco
curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, galaxyAPI::writeMemoryCallback); curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, galaxyAPI::writeMemoryCallback);
curl_easy_setopt(curlhandle, CURLOPT_WRITEDATA, &memory); curl_easy_setopt(curlhandle, CURLOPT_WRITEDATA, &memory);
curl_easy_perform(curlhandle);
std::string response = memory.str(); int retries = 0;
memory.str(std::string()); CURLcode result;
std::string response;
do
{
if (Globals::globalConfig.iWait > 0)
usleep(Globals::globalConfig.iWait); // Delay the request by specified time
result = curl_easy_perform(curlhandle);
response = memory.str();
memory.str(std::string());
}
while ((result != CURLE_OK) && response.empty() && (retries++ < Globals::globalConfig.iRetries));
curl_easy_setopt(curlhandle, CURLOPT_HTTPHEADER, NULL); curl_easy_setopt(curlhandle, CURLOPT_HTTPHEADER, NULL);
curl_slist_free_all(header); curl_slist_free_all(header);