mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 19:56:00 +00:00
General purpose function to retry on database timeout
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <backend/DBHelpers.h>
|
||||
#include <backend/SimpleCache.h>
|
||||
#include <backend/Types.h>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
namespace Backend {
|
||||
|
||||
class DatabaseTimeout : public std::exception
|
||||
@@ -16,6 +18,25 @@ class DatabaseTimeout : public std::exception
|
||||
}
|
||||
};
|
||||
|
||||
template <class F>
|
||||
auto
|
||||
retryOnTimeout(F func, size_t waitMs = 500)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
return func();
|
||||
}
|
||||
catch (DatabaseTimeout& t)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(waitMs));
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< __func__ << " function timed out. Retrying ... ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BackendInterface
|
||||
{
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user