ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
health_monitor Class Referencefinal

Monitors database connectivity and provides health status. More...

#include <health_monitor.hpp>

Collaboration diagram for health_monitor:
Collaboration graph

Public Types

using status_change_callback = std::function< void(bool available, const std::string &error_message)>
 Callback type for status change notifications.
 

Public Member Functions

 health_monitor (database_options options, std::chrono::seconds poll_interval=std::chrono::seconds(5))
 Construct a health monitor with database options.
 
 health_monitor (const health_monitor &)=delete
 
health_monitoroperator= (const health_monitor &)=delete
 
 health_monitor (health_monitor &&)=delete
 
health_monitoroperator= (health_monitor &&)=delete
 
void set_status_change_callback (status_change_callback callback)
 Set the callback to be invoked when database status changes.
 
bool is_available () const
 Check if the database is currently available.
 
std::string last_error () const
 Get the last error message if database is unavailable.
 
boost::asio::awaitable< void > run (boost::asio::io_context &io_context)
 Run the health monitor polling loop.
 
void stop ()
 Stop the health monitor.
 
bool check_health ()
 Perform a single health check.
 

Detailed Description

Monitors database connectivity and provides health status.

This class periodically checks database connectivity and maintains the current health status. It can notify listeners when the status changes, allowing the server to inform clients of database availability issues.

Usage:

health_monitor monitor(db_options, std::chrono::seconds(5));
// Set callback for status changes
monitor.set_status_change_callback([](bool available) {
if (!available) {
notify_clients_database_unavailable();
}
});
// Start monitoring
co_await monitor.run(io_context);
Monitors database connectivity and provides health status.
Definition health_monitor.hpp:59

Member Typedef Documentation

◆ status_change_callback

using status_change_callback = std::function<void(bool available, const std::string& error_message)>

Callback type for status change notifications.

The callback receives the new availability status (true = available, false = unavailable) and an optional error message when unavailable.

Constructor & Destructor Documentation

◆ health_monitor()

health_monitor ( database_options  options,
std::chrono::seconds  poll_interval = std::chrono::seconds(5) 
)
explicit

Construct a health monitor with database options.

Parameters
optionsDatabase connection options.
poll_intervalInterval between health checks.

Member Function Documentation

◆ set_status_change_callback()

void set_status_change_callback ( status_change_callback  callback)

Set the callback to be invoked when database status changes.

Parameters
callbackThe callback function.

◆ is_available()

bool is_available ( ) const

Check if the database is currently available.

Returns
true if the database is available, false otherwise.

◆ last_error()

std::string last_error ( ) const

Get the last error message if database is unavailable.

Returns
The error message, or empty string if database is available.

◆ run()

boost::asio::awaitable< void > run ( boost::asio::io_context &  io_context)

Run the health monitor polling loop.

This performs an initial check and then polls at the configured interval until stopped.

Parameters
io_contextThe io_context to run on.

◆ stop()

void stop ( )

Stop the health monitor.

Cancels the polling loop.

◆ check_health()

bool check_health ( )

Perform a single health check.

Can be called manually to check database connectivity.

Returns
true if database is available, false otherwise.
Here is the caller graph for this function: