#include <ored/utilities/fileio.hpp>
Definition at line 35 of file fileio.hpp.
◆ FileIO()
◆ maxRetries()
The maximum number of retries, defaults to 7.
Definition at line 43 of file fileio.cpp.
43{ return _s_maxRetries; }
◆ backoff()
◆ maxBackoff()
Definition at line 47 of file fileio.cpp.
47{ return _s_maxBackoff; }
◆ setMaxRetries()
void setMaxRetries |
( |
QuantLib::Size |
| ) |
|
|
static |
Definition at line 49 of file fileio.cpp.
49 {
50 LOG(
"Setting FileOpen max retries to " << n);
51 _s_maxRetries = n;
52}
#define LOG(text)
Logging Macro (Level = Notice)
◆ setBackoff()
void setBackoff |
( |
QuantLib::Real |
| ) |
|
|
static |
Definition at line 54 of file fileio.cpp.
54 {
55 LOG(
"Setting FileOpen backoff to " << b);
56 _s_backoff = b;
57}
◆ setMaxBackoff()
void setMaxBackoff |
( |
QuantLib::Real |
| ) |
|
|
static |
Definition at line 59 of file fileio.cpp.
59 {
60 LOG(
"Setting FileOpen max backoff to " << m);
61 _s_maxBackoff = m;
62}
◆ fopen()
FILE * fopen |
( |
const char * |
filename, |
|
|
const char * |
mode |
|
) |
| |
|
static |
Retry wrapper for std::fopen.
Definition at line 64 of file fileio.cpp.
64 {
65 FILE* fp;
66 Real currentBackoff =
backoff();
67
69 if (i > 0) {
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);
74 em.log();
75 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
76 Real nextBackoff = currentBackoff * 2;
78 }
79
80 fp = std::fopen(filename, mode);
81 if (fp)
82 break;
83 }
84
85 return fp;
86}
static QuantLib::Real backoff()
static QuantLib::Real maxBackoff()
static QuantLib::Size maxRetries()
The maximum number of retries, defaults to 7.
◆ create_directories()
bool create_directories |
( |
const path & |
p | ) |
|
|
static |
Retry wrapper for boost::filesystem::create_directories.
Definition at line 88 of file fileio.cpp.
88 {
89 bool res = false;
90 Real currentBackoff =
backoff();
91
93 if (i > 0) {
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);
98 em.log();
99 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
100 Real nextBackoff = currentBackoff * 2;
102 }
103
104 try {
105 res = boost::filesystem::create_directories(p);
106 if (res)
107 break;
108 } catch (...) {
109 }
110 }
111
112 return res;
113}
◆ remove_all()
bool remove_all |
( |
const path & |
p | ) |
|
|
static |
Retry wrapper for boost::filesystem::remove_all.
Definition at line 115 of file fileio.cpp.
115 {
116 bool res = false;
117 Real currentBackoff =
backoff();
118
120 if (i > 0) {
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);
125 em.log();
126 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
127 Real nextBackoff = currentBackoff * 2;
129 }
130
131 try {
132 res = boost::filesystem::remove_all(p);
133 if (res)
134 break;
135 } catch (...) {
136 }
137 }
138
139 return res;
140}