24#include <boost/filesystem/operations.hpp>
39static Size _s_maxRetries = 7;
40static Real _s_backoff = 0.5;
41static Real _s_maxBackoff = 30;
50 LOG(
"Setting FileOpen max retries to " << n);
55 LOG(
"Setting FileOpen backoff to " << b);
60 LOG(
"Setting FileOpen max backoff to " << m);
66 Real currentBackoff =
backoff();
70 auto em =
EventMessage(
"Error opening file '" + std::string(filename) +
"'. Retrying...",
"exception_message");
71 em.set(
"retry_count", i);
72 Real backoffMillis = currentBackoff * 1000;
73 em.set(
"retry_interval", backoffMillis);
75 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
76 Real nextBackoff = currentBackoff * 2;
80 fp = std::fopen(filename, mode);
90 Real currentBackoff =
backoff();
94 auto em =
EventMessage(
"Error creating directory '" + p.string() +
"'. Retrying...",
"exception_message");
95 em.set(
"retry_count", i);
96 Real backoffMillis = currentBackoff * 1000;
97 em.set(
"retry_interval", backoffMillis);
99 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
100 Real nextBackoff = currentBackoff * 2;
105 res = boost::filesystem::create_directories(p);
117 Real currentBackoff =
backoff();
121 auto em =
EventMessage(
"Error emptying directory '" + p.string() +
"'. Retrying...",
"exception_message");
122 em.set(
"retry_count", i);
123 Real backoffMillis = currentBackoff * 1000;
124 em.set(
"retry_interval", backoffMillis);
126 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
127 Real nextBackoff = currentBackoff * 2;
132 res = boost::filesystem::remove_all(p);
static void setMaxBackoff(QuantLib::Real)
static QuantLib::Real backoff()
static void setBackoff(QuantLib::Real)
static void setMaxRetries(QuantLib::Size)
static bool remove_all(const path &)
Retry wrapper for boost::filesystem::remove_all.
static QuantLib::Real maxBackoff()
static QuantLib::Size maxRetries()
The maximum number of retries, defaults to 7.
static bool create_directories(const path &)
Retry wrapper for boost::filesystem::create_directories.
static FILE * fopen(const char *, const char *)
Retry wrapper for std::fopen.
Wrapper class for retrying file IO operations.
Classes and functions for log message handling.
#define LOG(text)
Logging Macro (Level = Notice)
Serializable Credit Default Swap.
string conversion utilities