Google Cloud Pub/Sub C++ Client  1.32.1
A C++ Client Library for Google Cloud Pub/Sub
retry_policy.h
Go to the documentation of this file.
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_RETRY_POLICY_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_RETRY_POLICY_H
17 
18 #include "google/cloud/pubsub/version.h"
19 #include "google/cloud/internal/retry_policy.h"
20 #include "google/cloud/status.h"
21 
22 namespace google {
23 namespace cloud {
24 namespace pubsub_internal {
25 inline namespace GOOGLE_CLOUD_CPP_PUBSUB_NS {
26 /// Define the gRPC status code semantics for retrying requests.
27 struct RetryTraits {
28  static inline bool IsPermanentFailure(google::cloud::Status const& status) {
29  return status.code() != StatusCode::kOk &&
30  status.code() != StatusCode::kAborted &&
32  status.code() != StatusCode::kInternal &&
35  }
36 };
37 
38 } // namespace GOOGLE_CLOUD_CPP_PUBSUB_NS
39 } // namespace pubsub_internal
40 
41 namespace pubsub {
42 inline namespace GOOGLE_CLOUD_CPP_PUBSUB_NS {
43 
44 /// The base class for retry policies.
45 using RetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy<
46  pubsub_internal::RetryTraits>;
47 
48 /// A retry policy that limits based on time.
49 using LimitedTimeRetryPolicy =
50  ::google::cloud::internal::LimitedTimeRetryPolicy<
51  pubsub_internal::RetryTraits>;
52 
53 /// A retry policy that limits the number of times a request can fail.
54 using LimitedErrorCountRetryPolicy =
55  google::cloud::internal::LimitedErrorCountRetryPolicy<
56  pubsub_internal::RetryTraits>;
57 
58 } // namespace GOOGLE_CLOUD_CPP_PUBSUB_NS
59 } // namespace pubsub
60 } // namespace cloud
61 } // namespace google
62 
63 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_RETRY_POLICY_H