diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2025-02-14 16:28:57 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2025-02-17 21:31:24 +0200 |
commit | 4f9ab8e952cb16a311bd533842296a5bd2e9cc1c (patch) | |
tree | 8a8de9afc5850867d4847f81d7d9233b62452189 /mod/utility.cxx | |
parent | 62a6bd8d6bb576edf76c42db8ffb73fcb0f87fb7 (diff) |
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.
Diffstat (limited to 'mod/utility.cxx')
-rw-r--r-- | mod/utility.cxx | 23 |
1 files changed, 23 insertions, 0 deletions
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 <mod/utility.hxx> +#include <chrono> +#include <random> +#include <thread> // this_thread::sleep_for(), this_thread::yield() + #include <libbutl/path-pattern.hxx> +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<unsigned long> ( + 1, static_cast<unsigned long> (max_time)) (rand_gen)); + + this_thread::sleep_for (chrono::milliseconds (ms)); + } + else + this_thread::yield (); + } } |