mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-29 01:50:43 +00:00
Simplify the Job Queue:
This is a refactor aimed at cleaning up and simplifying the existing job queue. As of now, all jobs are cancelled at the same time and in the same way, so this commit removes the per-job cancellation token. If the need for such support is demonstrated, support can be re-added. * Revise documentation for ClosureCounter and Workers. * Simplify code, removing unnecessary function arguments and deduplicating expressions * Restructure job handlers to no longer need to pass a job's handle to the job.
This commit is contained in:
committed by
Nik Bougalis
parent
df02eb125f
commit
c2a08a1f26
@@ -360,7 +360,7 @@ ShardArchiveHandler::next(std::lock_guard<std::mutex> const& l)
|
||||
// to prevent holding up the lock if the downloader
|
||||
// sleeps.
|
||||
auto const& url{archives_.begin()->second};
|
||||
auto wrapper = jobCounter_.wrap([this, url, dstDir](Job&) {
|
||||
auto wrapper = jobCounter_.wrap([this, url, dstDir]() {
|
||||
auto const ssl = (url.scheme == "https");
|
||||
auto const defaultPort = ssl ? 443 : 80;
|
||||
|
||||
@@ -416,42 +416,41 @@ ShardArchiveHandler::complete(path dstPath)
|
||||
}
|
||||
|
||||
// Make lambdas mutable captured vars can be moved from
|
||||
auto wrapper =
|
||||
jobCounter_.wrap([=, dstPath = std::move(dstPath)](Job&) mutable {
|
||||
if (stopping_)
|
||||
return;
|
||||
auto wrapper = jobCounter_.wrap([=,
|
||||
dstPath = std::move(dstPath)]() mutable {
|
||||
if (stopping_)
|
||||
return;
|
||||
|
||||
// If not synced then defer and retry
|
||||
auto const mode{app_.getOPs().getOperatingMode()};
|
||||
if (mode != OperatingMode::FULL)
|
||||
{
|
||||
std::lock_guard lock(m_);
|
||||
timer_.expires_from_now(static_cast<std::chrono::seconds>(
|
||||
(static_cast<std::size_t>(OperatingMode::FULL) -
|
||||
static_cast<std::size_t>(mode)) *
|
||||
10));
|
||||
// If not synced then defer and retry
|
||||
auto const mode{app_.getOPs().getOperatingMode()};
|
||||
if (mode != OperatingMode::FULL)
|
||||
{
|
||||
std::lock_guard lock(m_);
|
||||
timer_.expires_from_now(static_cast<std::chrono::seconds>(
|
||||
(static_cast<std::size_t>(OperatingMode::FULL) -
|
||||
static_cast<std::size_t>(mode)) *
|
||||
10));
|
||||
|
||||
auto wrapper = timerCounter_.wrap(
|
||||
[=, dstPath = std::move(dstPath)](
|
||||
boost::system::error_code const& ec) mutable {
|
||||
if (ec != boost::asio::error::operation_aborted)
|
||||
complete(std::move(dstPath));
|
||||
});
|
||||
auto wrapper = timerCounter_.wrap(
|
||||
[=, dstPath = std::move(dstPath)](
|
||||
boost::system::error_code const& ec) mutable {
|
||||
if (ec != boost::asio::error::operation_aborted)
|
||||
complete(std::move(dstPath));
|
||||
});
|
||||
|
||||
if (!wrapper)
|
||||
onClosureFailed(
|
||||
"failed to wrap closure for operating mode timer",
|
||||
lock);
|
||||
else
|
||||
timer_.async_wait(*wrapper);
|
||||
}
|
||||
if (!wrapper)
|
||||
onClosureFailed(
|
||||
"failed to wrap closure for operating mode timer", lock);
|
||||
else
|
||||
{
|
||||
process(dstPath);
|
||||
std::lock_guard lock(m_);
|
||||
removeAndProceed(lock);
|
||||
}
|
||||
});
|
||||
timer_.async_wait(*wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
process(dstPath);
|
||||
std::lock_guard lock(m_);
|
||||
removeAndProceed(lock);
|
||||
}
|
||||
});
|
||||
|
||||
if (!wrapper)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user