replay/route: adds retry on network failures (#31948)

old-commit-hash: b8f5f50d39
pull/32199/head
Dean Lee 1 year ago committed by GitHub
parent 3e8fa28cef
commit 05d0243ff5
  1. 31
      tools/replay/route.cc
  2. 2
      tools/replay/route.h

@ -59,18 +59,27 @@ bool Route::load() {
return !segments_.empty();
}
bool Route::loadFromServer() {
QEventLoop loop;
HttpRequest http(nullptr, !Hardware::PC());
QObject::connect(&http, &HttpRequest::requestDone, [&](const QString &json, bool success, QNetworkReply::NetworkError error) {
if (error == QNetworkReply::ContentAccessDenied || error == QNetworkReply::AuthenticationRequiredError) {
qWarning() << ">> Unauthorized. Authenticate with tools/lib/auth.py <<";
bool Route::loadFromServer(int retries) {
for (int i = 1; i <= retries; ++i) {
QString result;
QEventLoop loop;
HttpRequest http(nullptr, !Hardware::PC());
QObject::connect(&http, &HttpRequest::requestDone, [&loop, &result](const QString &json, bool success, QNetworkReply::NetworkError err) {
result = json;
loop.exit((int)err);
});
http.sendRequest(CommaApi::BASE_URL + "/v1/route/" + route_.str + "/files");
auto err = (QNetworkReply::NetworkError)loop.exec();
if (err == QNetworkReply::NoError) {
return loadFromJson(result);
} else if (err == QNetworkReply::ContentAccessDenied || err == QNetworkReply::AuthenticationRequiredError) {
rWarning(">> Unauthorized. Authenticate with tools/lib/auth.py <<");
return false;
}
loop.exit(success ? loadFromJson(json) : 0);
});
http.sendRequest(CommaApi::BASE_URL + "/v1/route/" + route_.str + "/files");
return loop.exec();
rWarning("Retrying %d/%d", i, retries);
util::sleep_for(500);
}
return false;
}
bool Route::loadFromJson(const QString &json) {

@ -42,7 +42,7 @@ public:
protected:
bool loadFromLocal();
bool loadFromServer();
bool loadFromServer(int retries = 3);
bool loadFromJson(const QString &json);
void addFileToSegment(int seg_num, const QString &file);
RouteIdentifier route_ = {};

Loading…
Cancel
Save