aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp18
-rw-r--r--jobs/basejob.h6
2 files changed, 18 insertions, 6 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 9d5c5ed6..3ea13c83 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -53,6 +53,7 @@ class BaseJob::Private
{ }
void sendRequest();
+ const JobTimeoutConfig& getCurrentTimeoutConfig() const;
const ConnectionData* connection = nullptr;
@@ -69,8 +70,10 @@ class BaseJob::Private
QTimer timer;
QTimer retryTimer;
- size_t maxRetries = 3;
- size_t retriesTaken = 0;
+ QVector<JobTimeoutConfig> errorStrategy =
+ { { 90, 5 }, { 90, 10 }, { 120, 30 } };
+ int maxRetries = errorStrategy.size();
+ int retriesTaken = 0;
LoggingCategory logCat = JOBS;
};
@@ -297,16 +300,19 @@ void BaseJob::finishJob()
deleteLater();
}
+const JobTimeoutConfig& BaseJob::Private::getCurrentTimeoutConfig() const
+{
+ return errorStrategy[std::min(retriesTaken, errorStrategy.size() - 1)];
+}
+
BaseJob::duration_t BaseJob::getCurrentTimeout() const
{
- static const std::array<int, 4> timeouts = { 90, 90, 120, 120 };
- return timeouts[std::min(d->retriesTaken, timeouts.size() - 1)] * 1000;
+ return d->getCurrentTimeoutConfig().jobTimeout * 1000;
}
BaseJob::duration_t BaseJob::getNextRetryInterval() const
{
- static const std::array<int, 3> intervals = { 5, 10, 30 };
- return intervals[std::min(d->retriesTaken, intervals.size() - 1)] * 1000;
+ return d->getCurrentTimeoutConfig().nextRetryInterval * 1000;
}
BaseJob::duration_t BaseJob::millisToRetry() const
diff --git a/jobs/basejob.h b/jobs/basejob.h
index 66812774..aa4894bd 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -36,6 +36,12 @@ namespace QMatrixClient
enum class HttpVerb { Get, Put, Post, Delete };
+ struct JobTimeoutConfig
+ {
+ int jobTimeout;
+ int nextRetryInterval;
+ };
+
class BaseJob: public QObject
{
Q_OBJECT