From 4f9ab8e952cb16a311bd533842296a5bd2e9cc1c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 14 Feb 2025 16:28:57 +0200 Subject: Sleep for some short period of time before retrying after odb::recoverable exception Also increase the default maximum number of retries for configuration to 20 from 10. --- mod/utility.cxx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'mod/utility.cxx') diff --git a/mod/utility.cxx b/mod/utility.cxx index 5ca16a0..9b76a6e 100644 --- a/mod/utility.cxx +++ b/mod/utility.cxx @@ -3,8 +3,16 @@ #include +#include +#include +#include // this_thread::sleep_for(), this_thread::yield() + #include +using namespace std; + +static thread_local mt19937 rand_gen (random_device {} ()); + namespace brep { string @@ -66,4 +74,19 @@ namespace brep return r; } + + void + sleep_before_retry (size_t retry, size_t max_time) + { + if (retry != 0) + { + size_t ms ( + uniform_int_distribution ( + 1, static_cast (max_time)) (rand_gen)); + + this_thread::sleep_for (chrono::milliseconds (ms)); + } + else + this_thread::yield (); + } } -- cgit v1.1