olp-cpp-sdk  1.18.1
RetrySettings.h
1 /*
2  * Copyright (C) 2021-2023 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <chrono>
23 #include <functional>
24 
25 #include <olp/core/client/BackdownStrategy.h>
26 #include <olp/core/client/HttpResponse.h>
27 
28 namespace olp {
29 namespace client {
30 
34 CORE_API bool DefaultRetryCondition(const olp::client::HttpResponse& response);
35 
47 struct CORE_API RetrySettings {
52  using BackdownStrategy = std::function<std::chrono::milliseconds(
53  std::chrono::milliseconds, size_t)>;
54 
60  using RetryCondition = std::function<bool(const HttpResponse&)>;
61 
67  int max_attempts = 3;
68 
77  int timeout = 60;
78 
87  std::chrono::milliseconds connection_timeout = std::chrono::seconds(30);
88 
97  std::chrono::milliseconds transfer_timeout = std::chrono::seconds(30);
98 
103  int initial_backdown_period = 200;
104 
111 
116 };
117 
118 } // namespace client
119 } // namespace olp
This class represents the HTTP response created from the NetworkResponse and the request body.
Definition: HttpResponse.h:89
CORE_API bool DefaultRetryCondition(const olp::client::HttpResponse &response)
The default retry condition that disables retries.
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
Computes wait time for the next retry attempt via the exponential backoff with the added jitter.
Definition: BackdownStrategy.h:46
A collection of settings that controls how failed requests should be treated by the Data SDK.
Definition: RetrySettings.h:47
std::function< std::chrono::milliseconds(std::chrono::milliseconds, size_t)> BackdownStrategy
Calculates the number of retry timeouts based on the initial backdown duration and retries count.
Definition: RetrySettings.h:53
std::function< bool(const HttpResponse &)> RetryCondition
Checks whether the retry is desired.
Definition: RetrySettings.h:60