CodeFactor review
This commit is contained in:
@@ -150,28 +150,40 @@ namespace Scrobbling::ListenBrainz
|
|||||||
|
|
||||||
LOG(DEBUG) << "Client done. status = " << msg.status();
|
LOG(DEBUG) << "Client done. status = " << msg.status();
|
||||||
if (ec)
|
if (ec)
|
||||||
|
onClientDoneError(std::move(request), ec);
|
||||||
|
else
|
||||||
|
onClientDoneSuccess(std::move(request), msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SendQueue::onClientDoneError(Request request, Wt::AsioWrapper::error_code ec)
|
||||||
|
{
|
||||||
|
LOG(ERROR) << "Retry " << request._retryCount << ", client error: '" << ec.message() << "'";
|
||||||
|
|
||||||
|
// may be a network error, try again later
|
||||||
|
throttle(_defaultRetryWaitDuration);
|
||||||
|
|
||||||
|
if (request._retryCount++ < _maxRetryCount)
|
||||||
{
|
{
|
||||||
LOG(ERROR) << "Retry " << request._retryCount << ", client error: '" << ec.message() << "'";
|
_sendQueue[request._priority].emplace_front(std::move(request));
|
||||||
|
|
||||||
// may be a network error, try again later
|
|
||||||
throttle(_defaultRetryWaitDuration);
|
|
||||||
|
|
||||||
if (request._retryCount++ < _maxRetryCount)
|
|
||||||
{
|
|
||||||
_sendQueue[request._priority].emplace_front(std::move(request));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(ERROR) << "Too many retries, giving up operation and throttle";
|
|
||||||
if (request._onFailureFunc)
|
|
||||||
request._onFailureFunc();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG(ERROR) << "Too many retries, giving up operation and throttle";
|
||||||
|
if (request._onFailureFunc)
|
||||||
|
request._onFailureFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SendQueue::onClientDoneSuccess(Request request, const Wt::Http::Message& msg)
|
||||||
|
{
|
||||||
bool mustThrottle{};
|
bool mustThrottle{};
|
||||||
if (msg.status() == 429)
|
if (msg.status() == 429)
|
||||||
|
{
|
||||||
_sendQueue[request._priority].emplace_front(std::move(request));
|
_sendQueue[request._priority].emplace_front(std::move(request));
|
||||||
|
mustThrottle = true;
|
||||||
|
}
|
||||||
|
|
||||||
const auto remainingCount {headerReadAs<std::size_t>(msg, "X-RateLimit-Remaining")};
|
const auto remainingCount {headerReadAs<std::size_t>(msg, "X-RateLimit-Remaining")};
|
||||||
LOG(DEBUG) << "Remaining messages = " << (remainingCount ? *remainingCount : 0);
|
LOG(DEBUG) << "Remaining messages = " << (remainingCount ? *remainingCount : 0);
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ namespace Scrobbling::ListenBrainz
|
|||||||
void sendNextQueuedRequest();
|
void sendNextQueuedRequest();
|
||||||
bool sendRequest(const RequestData& request);
|
bool sendRequest(const RequestData& request);
|
||||||
void onClientDone(Wt::AsioWrapper::error_code ec, const Wt::Http::Message& msg);
|
void onClientDone(Wt::AsioWrapper::error_code ec, const Wt::Http::Message& msg);
|
||||||
|
void onClientDoneError(Request request, Wt::AsioWrapper::error_code ec);
|
||||||
|
void onClientDoneSuccess(Request request, const Wt::Http::Message& msg);
|
||||||
void throttle(std::chrono::seconds duration);
|
void throttle(std::chrono::seconds duration);
|
||||||
|
|
||||||
const std::size_t _maxRetryCount {2};
|
const std::size_t _maxRetryCount {2};
|
||||||
|
|||||||
Reference in New Issue
Block a user