1+ #include < darabonba/Core.hpp>
2+ #include < darabonba/test.hpp>
3+ #include < darabonba/policy/Retry.hpp>
4+ #include < darabonba/Runtime.hpp>
5+ #include < darabonba/Exception.hpp>
6+ using namespace std ;
7+ using json = nlohmann::json;
8+ namespace Darabonba
9+ {
10+
11+ /* *
12+ Init Func
13+ */
14+ Darabonba::Client::Client (){
15+ }
16+
17+
18+ void Client::testAPI () {
19+ Darabonba::RuntimeOptions runtime_ (json ({
20+ }));
21+
22+ shared_ptr<Darabonba::Http::Request> _lastRequest = nullptr ;
23+ shared_ptr<Darabonba::Http::MCurlResponse> _lastResponse = nullptr ;
24+ Darabonba::Exception _lastException;
25+ int _retriesAttempted = 0 ;
26+ Darabonba::Policy::RetryPolicyContext _context = json ({
27+ {" retriesAttempted" , _retriesAttempted}
28+ });
29+ while (Darabonba::allowRetry (runtime_.retryOptions (), _context)) {
30+ if (_retriesAttempted > 0 ) {
31+ int _backoffTime = Darabonba::getBackoffTime (runtime_.retryOptions (), _context);
32+ if (_backoffTime > 0 ) {
33+ Darabonba::sleep (_backoffTime);
34+ }
35+ }
36+ _retriesAttempted++;
37+ try {
38+ Darabonba::Http::Request request_ = Darabonba::Http::Request ();
39+ _lastRequest = make_shared<Darabonba::Http::Request>(request_);
40+ auto futureResp_ = Darabonba::Core::doAction (request_, runtime_);
41+ shared_ptr<Darabonba::Http::MCurlResponse> response_ = futureResp_.get ();
42+ _lastResponse = response_;
43+
44+ return ;
45+ } catch (const Darabonba::Exception& ex) {
46+ _context = Darabonba::Policy::RetryPolicyContext (json ({
47+ {" retriesAttempted" , _retriesAttempted},
48+ {" lastRequest" , _lastRequest},
49+ {" lastResponse" , _lastResponse},
50+ {" exception" , ex},
51+ }));
52+ continue ;
53+ }
54+ }
55+
56+ throw *_context.exception ();
57+ }
58+
59+ /* *
60+ testFunc
61+ */
62+ void Client::testFunc () {
63+ }
64+ } // namespace Darabonba
0 commit comments