Use boost asio post to fix build

This commit is contained in:
emeric
2025-02-10 16:54:25 +01:00
parent cefa60e734
commit c9fb398196
3 changed files with 19 additions and 16 deletions
+3 -2
View File
@@ -21,6 +21,7 @@
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/dispatch.hpp>
#include <boost/asio/post.hpp>
#include "core/Exception.hpp"
#include "core/ILogger.hpp"
@@ -64,9 +65,9 @@ namespace lms::core::http
, _baseUrl{ baseUrl }
{
_client.done().connect([this](Wt::AsioWrapper::error_code ec, const Wt::Http::Message& msg) {
_strand.dispatch([this, ec, msg = std::move(msg)] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, ec, msg = std::move(msg)] {
onClientDone(ec, msg);
});
}));
});
}
@@ -24,6 +24,7 @@
#include <Wt/Json/Serializer.h>
#include <Wt/Json/Value.h>
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/post.hpp>
#include "core/IConfig.hpp"
#include "core/Service.hpp"
@@ -132,9 +133,9 @@ namespace lms::feedback::listenBrainz
request.message.addHeader("Content-Type", "application/json");
request.onSuccessFunc = [this, type, starredTrackId](std::string_view /*msgBody*/) {
_strand.dispatch([this, type, starredTrackId] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, type, starredTrackId] {
onFeedbackSent(type, starredTrackId);
});
}));
};
_client.sendPOSTRequest(std::move(request));
}
@@ -295,13 +296,13 @@ namespace lms::feedback::listenBrainz
void FeedbacksSynchronizer::onSyncEnded(UserContext& context)
{
_strand.dispatch([this, &context] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, &context] {
LOG(INFO, "Feedback sync done for user '" << context.listenBrainzUserName << "', fetched: " << context.fetchedFeedbackCount << ", matched: " << context.matchedFeedbackCount << ", imported: " << context.importedFeedbackCount);
context.syncing = false;
if (!isSyncing())
scheduleSync(_syncFeedbacksPeriod);
});
}));
}
void FeedbacksSynchronizer::enqueValidateToken(UserContext& context)
@@ -344,7 +345,7 @@ namespace lms::feedback::listenBrainz
request.priority = core::http::ClientRequestParameters::Priority::Low;
request.onSuccessFunc = [this, &context](std::string_view msgBody) {
std::string msgBodyCopy{ msgBody };
_strand.dispatch([this, msgBodyCopy, &context] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, msgBodyCopy, &context] {
LOG(DEBUG, "Current feedback count = " << (context.feedbackCount ? *context.feedbackCount : 0) << " for user '" << context.listenBrainzUserName << "'");
const auto totalFeedbackCount = parseTotalFeedbackCount(msgBodyCopy);
@@ -358,7 +359,7 @@ namespace lms::feedback::listenBrainz
enqueGetFeedbacks(context);
else
onSyncEnded(context);
});
}));
};
request.onFailureFunc = [this, &context] {
onSyncEnded(context);
@@ -376,7 +377,7 @@ namespace lms::feedback::listenBrainz
request.priority = core::http::ClientRequestParameters::Priority::Low;
request.onSuccessFunc = [this, &context](std::string_view msgBody) {
std::string msgBodyCopy{ msgBody };
_strand.dispatch([this, msgBodyCopy, &context] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, msgBodyCopy, &context] {
const std::size_t fetchedFeedbackCount{ processGetFeedbacks(msgBodyCopy, context) };
if (fetchedFeedbackCount == 0 // no more thing available on server
|| context.fetchedFeedbackCount >= context.feedbackCount // we may miss something, but we will get it next time
@@ -388,7 +389,7 @@ namespace lms::feedback::listenBrainz
{
enqueGetFeedbacks(context);
}
});
}));
};
request.onFailureFunc = [this, &context] {
onSyncEnded(context);
@@ -24,6 +24,7 @@
#include <Wt/Json/Serializer.h>
#include <Wt/Json/Value.h>
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/post.hpp>
#include "ListensParser.hpp"
#include "core/IConfig.hpp"
@@ -245,14 +246,14 @@ namespace lms::scrobbling::listenBrainz
request.priority = core::http::ClientRequestParameters::Priority::Normal;
request.onSuccessFunc = [this, timedListen](std::string_view) {
_strand.dispatch([this, timedListen] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, timedListen] {
if (saveListen(timedListen, db::SyncState::Synchronized))
{
UserContext& context{ getUserContext(timedListen.userId) };
if (context.listenCount)
(*context.listenCount)++;
}
});
}));
};
// on failure, this listen will be sent during the next sync
}
@@ -430,13 +431,13 @@ namespace lms::scrobbling::listenBrainz
void ListensSynchronizer::onSyncEnded(UserContext& context)
{
_strand.dispatch([this, &context] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, &context] {
LOG(INFO, "Sync done for user '" << context.listenBrainzUserName << "', fetched: " << context.fetchedListenCount << ", matched: " << context.matchedListenCount << ", imported: " << context.importedListenCount);
context.syncing = false;
if (!isSyncing())
scheduleSync(_syncListensPeriod);
});
}));
}
void ListensSynchronizer::enqueValidateToken(UserContext& context)
@@ -479,7 +480,7 @@ namespace lms::scrobbling::listenBrainz
request.priority = core::http::ClientRequestParameters::Priority::Low;
request.onSuccessFunc = [this, &context](std::string_view msgBody) {
const auto listenCount{ parseListenCount(msgBody) };
_strand.dispatch([this, listenCount, &context] {
boost::asio::post(boost::asio::bind_executor(_strand, [this, listenCount, &context] {
if (listenCount)
LOG(DEBUG, "Listen count for listenbrainz user '" << context.listenBrainzUserName << "' = " << *listenCount);
@@ -494,7 +495,7 @@ namespace lms::scrobbling::listenBrainz
context.maxDateTime = Wt::WDateTime::currentDateTime();
enqueGetListens(context);
});
}));
};
request.onFailureFunc = [this, &context] {
onSyncEnded(context);