Google Cloud Pub/Sub C++ Client  1.42.0
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 // https://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 {
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 &&
31  status.code() != StatusCode::kInternal &&
34  }
35 };
36 
38 } // namespace pubsub_internal
39 
40 namespace pubsub {
42 
43 /// The base class for retry policies.
44 using RetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy<
45  pubsub_internal::RetryTraits>;
46 
47 /// A retry policy that limits based on time.
48 using LimitedTimeRetryPolicy =
49  ::google::cloud::internal::LimitedTimeRetryPolicy<
50  pubsub_internal::RetryTraits>;
51 
52 /// A retry policy that limits the number of times a request can fail.
53 using LimitedErrorCountRetryPolicy =
54  google::cloud::internal::LimitedErrorCountRetryPolicy<
55  pubsub_internal::RetryTraits>;
56 
58 } // namespace pubsub
59 } // namespace cloud
60 } // namespace google
61 
62 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_RETRY_POLICY_H