aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-08-04 13:32:57 +0200
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-08-04 13:32:57 +0200
commitd88663890261c2c276cd76576655b137a8758670 (patch)
tree154c3e3b84e96a18b97a37bd9aaa03a85437dd66
parenteedfd50f9661149f804f169c458b6ef25f96a834 (diff)
downloadlibquotient-d88663890261c2c276cd76576655b137a8758670.tar.gz
libquotient-d88663890261c2c276cd76576655b137a8758670.zip
BaseJob: go for a retry on IncorrectResponse
The most frequent occurence of IncorrectResponse so far is a proxy/CDN failure. This is not a grave error; there's a chance that the retry will succeed. In the worst case the job will fail after 3 identical errors (except SyncJob that will try to get through forever - but SyncJob failures should still be indicated in the client's UI in some non-intrusive way).
-rw-r--r--lib/jobs/basejob.cpp55
1 files changed, 31 insertions, 24 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp
index d6d48d2f..1f0e84ba 100644
--- a/lib/jobs/basejob.cpp
+++ b/lib/jobs/basejob.cpp
@@ -586,33 +586,40 @@ void BaseJob::stop()
void BaseJob::finishJob()
{
stop();
- if (error() == TooManyRequests) {
+ switch(error()) {
+ case TooManyRequests:
emit rateLimited();
d->connection->submit(this);
return;
- }
- if (error() == Unauthorised && !d->needsToken
- && !d->connection->accessToken().isEmpty()) {
- // Rerun with access token (extension of the spec while
- // https://github.com/matrix-org/matrix-doc/issues/701 is pending)
- d->connection->setNeedsToken(objectName());
- qCWarning(d->logCat) << this << "re-running with authentication";
- emit retryScheduled(d->retriesTaken, 0);
- d->connection->submit(this);
- return;
- }
- if ((error() == NetworkError || error() == Timeout)
- && d->retriesTaken < d->maxRetries) {
- // TODO: The whole retrying thing should be put to Connection(Manager)
- // otherwise independently retrying jobs make a bit of notification
- // storm towards the UI.
- const seconds retryIn = error() == Timeout ? 0s : getNextRetryInterval();
- ++d->retriesTaken;
- qCWarning(d->logCat).nospace() << this << ": retry #" << d->retriesTaken
- << " in " << retryIn.count() << " s";
- d->retryTimer.start(retryIn);
- emit retryScheduled(d->retriesTaken, milliseconds(retryIn).count());
- return;
+ case Unauthorised:
+ if (!d->needsToken && !d->connection->accessToken().isEmpty()) {
+ // Rerun with access token (extension of the spec while
+ // https://github.com/matrix-org/matrix-doc/issues/701 is pending)
+ d->connection->setNeedsToken(objectName());
+ qCWarning(d->logCat) << this << "re-running with authentication";
+ emit retryScheduled(d->retriesTaken, 0);
+ d->connection->submit(this);
+ return;
+ }
+ break;
+ case NetworkError:
+ case IncorrectResponse:
+ case Timeout:
+ if (d->retriesTaken < d->maxRetries) {
+ // TODO: The whole retrying thing should be put to
+ // Connection(Manager) otherwise independently retrying jobs make a
+ // bit of notification storm towards the UI.
+ const seconds retryIn = error() == Timeout ? 0s
+ : getNextRetryInterval();
+ ++d->retriesTaken;
+ qCWarning(d->logCat).nospace()
+ << this << ": retry #" << d->retriesTaken << " in "
+ << retryIn.count() << " s";
+ d->retryTimer.start(retryIn);
+ emit retryScheduled(d->retriesTaken, milliseconds(retryIn).count());
+ return;
+ }
+ default:;
}
Q_ASSERT(status().code != Pending);