22#include "data/BackendInterface.hpp"
23#include "data/LedgerCacheSaver.hpp"
24#include "etl/ETLServiceInterface.hpp"
26#include "feed/SubscriptionManagerInterface.hpp"
27#include "util/CoroutineGroup.hpp"
28#include "util/log/Logger.hpp"
29#include "web/interface/Concepts.hpp"
31#include <boost/asio/executor_work_guard.hpp>
32#include <boost/asio/io_context.hpp>
33#include <boost/asio/spawn.hpp>
44 boost::asio::io_context ctx_;
46 std::function<void()> onCompleteCallback_;
60 setOnStop(std::function<
void(boost::asio::yield_context)> cb);
88 template <web::SomeServer ServerType, data::SomeLedgerCacheSaver LedgerCacheSaverType>
89 static std::function<void(boost::asio::yield_context)>
96 LedgerCacheSaverType& cacheSaver,
97 boost::asio::io_context& ioc
100 return [&](boost::asio::yield_context yield) {
104 coroutineGroup.
spawn(yield, [&server](
auto innerYield) {
105 server.stop(innerYield);
108 coroutineGroup.
spawn(yield, [&balancer](
auto innerYield) {
109 balancer.
stop(innerYield);
117 subscriptions.
stop();
123 cacheSaver.waitToFinish();
Application stopper class. On stop it will create a new thread to run all the shutdown tasks.
Definition Stopper.hpp:43
void setOnComplete(std::function< void()> cb)
Set the callback to be called when graceful shutdown completes.
Definition Stopper.cpp:50
static std::function< void(boost::asio::yield_context)> makeOnStopCallback(ServerType &server, etl::LoadBalancerInterface &balancer, etl::ETLServiceInterface &etl, feed::SubscriptionManagerInterface &subscriptions, data::BackendInterface &backend, LedgerCacheSaverType &cacheSaver, boost::asio::io_context &ioc)
Create a callback to be called on application stop.
Definition Stopper.hpp:90
~Stopper()
Destroy the Stopper object.
Definition Stopper.cpp:32
void setOnStop(std::function< void(boost::asio::yield_context)> cb)
Set the callback to be called when the application is stopped.
Definition Stopper.cpp:39
void stop()
Stop the application and run the shutdown tasks.
Definition Stopper.cpp:56
The interface to the database used by Clio.
Definition BackendInterface.hpp:139
virtual void waitForWritesToFinish()=0
Wait for all pending writes to finish.
An interface for LoadBalancer.
Definition LoadBalancerInterface.hpp:59
virtual void stop(boost::asio::yield_context yield)=0
Stop the load balancer. This will stop all subscription sources.
Interface of subscription manager. A subscription manager is responsible for managing the subscriptio...
Definition SubscriptionManagerInterface.hpp:44
virtual void stop()=0
Stop the SubscriptionManager and wait for all jobs to finish.
CoroutineGroup is a helper class to manage a group of coroutines. It allows to spawn multiple corouti...
Definition CoroutineGroup.hpp:37
void asyncWait(boost::asio::yield_context yield)
Wait for all the coroutines in the group to finish.
Definition CoroutineGroup.cpp:72
bool spawn(boost::asio::yield_context yield, std::function< void(boost::asio::yield_context)> fn)
Spawn a new coroutine in the group.
Definition CoroutineGroup.cpp:46
static void shutdown()
Shutdown spdlog to guarantee output is not lost.
Definition Logger.cpp:381
static Logger::Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::NFO severity.
Definition Logger.cpp:402
This is a base class for any ETL service implementations.
Definition ETLServiceInterface.hpp:36