diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-25 20:00:24 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-25 20:00:24 +0900 |
commit | 37e807b7e4b8991353802b38da226ef47b8848ec (patch) | |
tree | 452e249ca5d4b7f3ab9f71f6672f2b01fe5e6b00 /jobs | |
parent | 155da0f2bdd831f59defd784e98fa9d4e7cea97e (diff) | |
download | libquotient-37e807b7e4b8991353802b38da226ef47b8848ec.tar.gz libquotient-37e807b7e4b8991353802b38da226ef47b8848ec.zip |
BaseJob: consolidate job timeout configuration
This prepares the backend to enable timeouts/retry intervals configurable from clients.
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/basejob.cpp | 18 | ||||
-rw-r--r-- | jobs/basejob.h | 6 |
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 |