|
ORE Studio 0.0.4
|
Monitors database connectivity and provides health status. More...
#include <health_monitor.hpp>

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_monitor & | operator= (const health_monitor &)=delete |
| health_monitor (health_monitor &&)=delete | |
| health_monitor & | operator= (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. | |
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:
| 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.
|
explicit |
Construct a health monitor with database options.
| options | Database connection options. |
| poll_interval | Interval between health checks. |
| void set_status_change_callback | ( | status_change_callback | callback | ) |
Set the callback to be invoked when database status changes.
| callback | The callback function. |
| 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.
This performs an initial check and then polls at the configured interval until stopped.
| io_context | The io_context to run on. |
| void stop | ( | ) |
Stop the health monitor.
Cancels the polling loop.
| bool check_health | ( | ) |
Perform a single health check.
Can be called manually to check database connectivity.
