diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-23 13:02:04 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-23 13:03:50 +0200 |
commit | 4141b5e8e6296ca8ab94553e27257f8c2b107461 (patch) | |
tree | 02c5a45a7e6736c24d76dbb24eeb468f1ced11d9 /common/messagequeue.cpp | |
parent | 6746247a49f09287ae4924c5c3df791f9bf61cbc (diff) | |
download | sink-4141b5e8e6296ca8ab94553e27257f8c2b107461.tar.gz sink-4141b5e8e6296ca8ab94553e27257f8c2b107461.zip |
Less noise and better error handling.
Trying to read from non-existant databases no longer prints error
messages.
Diffstat (limited to 'common/messagequeue.cpp')
-rw-r--r-- | common/messagequeue.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index ab4b1cf..f8bcd46 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp | |||
@@ -113,7 +113,6 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu | |||
113 | 113 | ||
114 | KAsync::Job<void> MessageQueue::dequeueBatch(int maxBatchSize, const std::function<KAsync::Job<void>(const QByteArray &)> &resultHandler) | 114 | KAsync::Job<void> MessageQueue::dequeueBatch(int maxBatchSize, const std::function<KAsync::Job<void>(const QByteArray &)> &resultHandler) |
115 | { | 115 | { |
116 | Trace() << "Dequeue batch"; | ||
117 | auto resultCount = QSharedPointer<int>::create(0); | 116 | auto resultCount = QSharedPointer<int>::create(0); |
118 | return KAsync::start<void>([this, maxBatchSize, resultHandler, resultCount](KAsync::Future<void> &future) { | 117 | return KAsync::start<void>([this, maxBatchSize, resultHandler, resultCount](KAsync::Future<void> &future) { |
119 | int count = 0; | 118 | int count = 0; |
@@ -123,14 +122,12 @@ KAsync::Job<void> MessageQueue::dequeueBatch(int maxBatchSize, const std::functi | |||
123 | return true; | 122 | return true; |
124 | } | 123 | } |
125 | *resultCount += 1; | 124 | *resultCount += 1; |
126 | Trace() << "Dequeue value"; | ||
127 | //We need a copy of the key here, otherwise we can't store it in the lambda (the pointers will become invalid) | 125 | //We need a copy of the key here, otherwise we can't store it in the lambda (the pointers will become invalid) |
128 | mPendingRemoval << QByteArray(key.constData(), key.size()); | 126 | mPendingRemoval << QByteArray(key.constData(), key.size()); |
129 | 127 | ||
130 | waitCondition << resultHandler(value).exec(); | 128 | waitCondition << resultHandler(value).exec(); |
131 | 129 | ||
132 | count++; | 130 | count++; |
133 | Trace() << count << maxBatchSize; | ||
134 | if (count < maxBatchSize) { | 131 | if (count < maxBatchSize) { |
135 | return true; | 132 | return true; |
136 | } | 133 | } |
@@ -145,7 +142,7 @@ KAsync::Job<void> MessageQueue::dequeueBatch(int maxBatchSize, const std::functi | |||
145 | ::waitForCompletion(waitCondition).then<void>([this, resultCount, &future]() { | 142 | ::waitForCompletion(waitCondition).then<void>([this, resultCount, &future]() { |
146 | processRemovals(); | 143 | processRemovals(); |
147 | if (*resultCount == 0) { | 144 | if (*resultCount == 0) { |
148 | future.setError(-1, "No message found"); | 145 | future.setError(static_cast<int>(ErrorCodes::NoMessageFound), "No message found"); |
149 | future.setFinished(); | 146 | future.setFinished(); |
150 | } else { | 147 | } else { |
151 | if (isEmpty()) { | 148 | if (isEmpty()) { |
@@ -160,16 +157,20 @@ KAsync::Job<void> MessageQueue::dequeueBatch(int maxBatchSize, const std::functi | |||
160 | bool MessageQueue::isEmpty() | 157 | bool MessageQueue::isEmpty() |
161 | { | 158 | { |
162 | int count = 0; | 159 | int count = 0; |
163 | mStorage.createTransaction(Akonadi2::Storage::ReadOnly).scan("", [&count, this](const QByteArray &key, const QByteArray &value) -> bool { | 160 | auto t = mStorage.createTransaction(Akonadi2::Storage::ReadOnly); |
164 | if (!Akonadi2::Storage::isInternalKey(key) && !mPendingRemoval.contains(key)) { | 161 | auto db = t.openDatabase(); |
165 | count++; | 162 | if (db) { |
166 | return false; | 163 | db.scan("", [&count, this](const QByteArray &key, const QByteArray &value) -> bool { |
167 | } | 164 | if (!Akonadi2::Storage::isInternalKey(key) && !mPendingRemoval.contains(key)) { |
168 | return true; | 165 | count++; |
169 | }, | 166 | return false; |
170 | [](const Akonadi2::Storage::Error &error) { | 167 | } |
171 | ErrorMsg() << "Error while checking if empty" << error.message; | 168 | return true; |
172 | }); | 169 | }, |
170 | [](const Akonadi2::Storage::Error &error) { | ||
171 | ErrorMsg() << "Error while checking if empty" << error.message; | ||
172 | }); | ||
173 | } | ||
173 | return count == 0; | 174 | return count == 0; |
174 | } | 175 | } |
175 | 176 | ||