comparison Framework/TransferToolbox.cpp @ 10:c9e28e31262e

new option: MaxHttpRetries
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Mar 2019 15:26:49 +0100
parents 7e207ade2f1a
children b06103a50c95
comparison
equal deleted inserted replaced
9:7e207ade2f1a 10:c9e28e31262e
19 19
20 #include "TransferToolbox.h" 20 #include "TransferToolbox.h"
21 21
22 #include <Core/Logging.h> 22 #include <Core/Logging.h>
23 #include <Core/OrthancException.h> 23 #include <Core/OrthancException.h>
24 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
24 25
25 #include <boost/math/special_functions/round.hpp> 26 #include <boost/math/special_functions/round.hpp>
27 #include <boost/thread/thread.hpp>
26 28
27 29
28 namespace OrthancPlugins 30 namespace OrthancPlugins
29 { 31 {
30 unsigned int ConvertToMegabytes(uint64_t value) 32 unsigned int ConvertToMegabytes(uint64_t value)
71 73
72 default: 74 default:
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 75 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
74 } 76 }
75 } 77 }
78
79
80 bool DoPostPeer(Json::Value& answer,
81 const OrthancPeers& peers,
82 size_t peerIndex,
83 const std::string& uri,
84 const std::string& body,
85 unsigned int maxRetries)
86 {
87 unsigned int retry = 0;
88
89 for (;;)
90 {
91 try
92 {
93 if (peers.DoPost(answer, peerIndex, uri, body))
94 {
95 return true;
96 }
97 }
98 catch (Orthanc::OrthancException&)
99 {
100 }
101
102 if (retry >= maxRetries)
103 {
104 return false;
105 }
106 else
107 {
108 // Wait 1 second before retrying
109 boost::this_thread::sleep(boost::posix_time::seconds(1));
110 retry++;
111 }
112 }
113 }
114
115
116 bool DoPostPeer(Json::Value& answer,
117 const OrthancPeers& peers,
118 const std::string& peerName,
119 const std::string& uri,
120 const std::string& body,
121 unsigned int maxRetries)
122 {
123 size_t index;
124
125 return (peers.LookupName(index, peerName) &&
126 DoPostPeer(answer, peers, index, uri, body, maxRetries));
127 }
128
129
130 bool DoDeletePeer(const OrthancPeers& peers,
131 size_t peerIndex,
132 const std::string& uri,
133 unsigned int maxRetries)
134 {
135 unsigned int retry = 0;
136
137 for (;;)
138 {
139 try
140 {
141 if (peers.DoDelete(peerIndex, uri))
142 {
143 return true;
144 }
145 }
146 catch (Orthanc::OrthancException&)
147 {
148 }
149
150 if (retry >= maxRetries)
151 {
152 return false;
153 }
154 else
155 {
156 // Wait 1 second before retrying
157 boost::this_thread::sleep(boost::posix_time::seconds(1));
158 retry++;
159 }
160 }
161 }
76 } 162 }