mirror of
https://github.com/XRPLF/clio.git
synced 2026-06-03 08:46:42 +00:00
feat: Graceful shutdown with old web server (#2786)
- Stop accepting connections during graceful shutdown in the old web server - Stop all the services before Clio exits - Move cache saving into stop callback
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "util/StopHelper.hpp"
|
||||
|
||||
#include "util/Spawn.hpp"
|
||||
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
@@ -37,7 +39,7 @@ void
|
||||
StopHelper::asyncWaitForStop(boost::asio::yield_context yield)
|
||||
{
|
||||
boost::asio::steady_timer timer{yield.get_executor(), std::chrono::steady_clock::duration::max()};
|
||||
onStopReady_.connect([&timer]() { timer.cancel(); });
|
||||
onStopReady_.connect([&]() { util::spawn(yield, [&timer](auto&&) { timer.cancel(); }); });
|
||||
boost::system::error_code error;
|
||||
if (!*stopped_)
|
||||
timer.async_wait(yield[error]);
|
||||
|
||||
@@ -36,6 +36,16 @@ class StopHelper {
|
||||
std::unique_ptr<std::atomic_bool> stopped_ = std::make_unique<std::atomic_bool>(false);
|
||||
|
||||
public:
|
||||
StopHelper() = default;
|
||||
~StopHelper() = default;
|
||||
|
||||
StopHelper(StopHelper&&) = delete;
|
||||
StopHelper&
|
||||
operator=(StopHelper&&) = delete;
|
||||
StopHelper(StopHelper const&) = delete;
|
||||
StopHelper&
|
||||
operator=(StopHelper const&) = delete;
|
||||
|
||||
/**
|
||||
* @brief Notify that the class is ready to stop.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user