3#include "cluster/Concepts.hpp"
4#include "data/BackendInterface.hpp"
5#include "data/LedgerCacheSaver.hpp"
6#include "etl/ETLServiceInterface.hpp"
8#include "feed/SubscriptionManagerInterface.hpp"
9#include "util/CoroutineGroup.hpp"
10#include "util/log/Logger.hpp"
11#include "web/interface/Concepts.hpp"
13#include <boost/asio/executor_work_guard.hpp>
14#include <boost/asio/io_context.hpp>
15#include <boost/asio/spawn.hpp>
27 boost::asio::io_context ctx_;
29 std::function<void()> onCompleteCallback_;
43 setOnStop(std::function<
void(boost::asio::yield_context)> cb);
76 static std::function<void(boost::asio::yield_context)>
83 LedgerCacheSaverType& cacheSaver,
84 ClusterCommunicationServiceType& clusterCommunicationService,
85 boost::asio::io_context& ioc
88 return [&](boost::asio::yield_context yield) {
92 coroutineGroup.
spawn(yield, [&server](
auto innerYield) {
93 server.stop(innerYield);
96 coroutineGroup.
spawn(yield, [&balancer](
auto innerYield) {
97 balancer.
stop(innerYield);
102 clusterCommunicationService.stop();
107 subscriptions.
stop();
113 cacheSaver.waitToFinish();
Application stopper class. On stop it will create a new thread to run all the shutdown tasks.
Definition Stopper.hpp:26
void setOnComplete(std::function< void()> cb)
Set the callback to be called when graceful shutdown completes.
Definition Stopper.cpp:31
~Stopper()
Destroy the Stopper object.
Definition Stopper.cpp:13
void setOnStop(std::function< void(boost::asio::yield_context)> cb)
Set the callback to be called when the application is stopped.
Definition Stopper.cpp:20
void stop()
Stop the application and run the shutdown tasks.
Definition Stopper.cpp:37
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, ClusterCommunicationServiceType &clusterCommunicationService, boost::asio::io_context &ioc)
Create a callback to be called on application stop.
Definition Stopper.hpp:77
The interface to the database used by Clio.
Definition BackendInterface.hpp:125
virtual void waitForWritesToFinish()=0
Wait for all pending writes to finish.
An interface for LoadBalancer.
Definition LoadBalancerInterface.hpp:40
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:25
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:18
void asyncWait(boost::asio::yield_context yield)
Wait for all the coroutines in the group to finish.
Definition CoroutineGroup.cpp:60
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:31
static void shutdown()
Shutdown spdlog to guarantee output is not lost.
Definition Logger.cpp:384
static Logger::Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::NFO severity.
Definition Logger.cpp:406
Definition Concepts.hpp:18
A concept for a class that can save ledger cache asynchronously.
Definition LedgerCacheSaver.hpp:21
Definition Concepts.hpp:36
This is a base class for any ETL service implementations.
Definition ETLServiceInterface.hpp:17