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