15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLLING_POLICY_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLLING_POLICY_H
18#include "google/cloud/internal/backoff_policy.h"
19#include "google/cloud/internal/retry_policy.h"
20#include "google/cloud/status.h"
21#include "google/cloud/version.h"
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
53
54
55
56
57
58
62
63
64
65
66
67
68
69
73
74
75 virtual std::chrono::milliseconds
WaitPeriod() = 0;
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93template <
typename Retry,
typename Backoff>
97 : retry_prototype_(std::move(retry_policy)),
98 backoff_prototype_(std::move(backoff_policy)),
99 retry_clone_(maybe_deref(retry_prototype_).clone()),
100 backoff_clone_(maybe_deref(backoff_prototype_).clone()) {}
105 backoff_prototype_));
109 return retry_clone_->OnFailure(status);
112 std::chrono::milliseconds
WaitPeriod()
override {
113 return backoff_clone_->OnCompletion();
117 template <
typename T>
118 T& maybe_deref(T& v) {
121 template <
typename T>
122 T& maybe_deref(std::shared_ptr<T>& v) {
126 Retry retry_prototype_;
127 Backoff backoff_prototype_;
129 std::unique_ptr<internal::RetryPolicy> retry_clone_;
130 std::unique_ptr<internal::BackoffPolicy> backoff_clone_;
Construct a polling policy from existing Retry and Backoff policies.
Definition: polling_policy.h:94
bool OnFailure(Status const &status) override
A callback to indicate that a polling attempt failed.
Definition: polling_policy.h:108
std::unique_ptr< PollingPolicy > clone() const override
Return a copy of the current policy.
Definition: polling_policy.h:102
std::chrono::milliseconds WaitPeriod() override
How long should the polling loop wait before trying again.
Definition: polling_policy.h:112
GenericPollingPolicy(Retry retry_policy, Backoff backoff_policy)
Definition: polling_policy.h:96
Control the Cloud C++ client library behavior with respect to polling on long running operations.
Definition: polling_policy.h:48
virtual std::chrono::milliseconds WaitPeriod()=0
How long should the polling loop wait before trying again.
virtual bool OnFailure(Status const &status)=0
A callback to indicate that a polling attempt failed.
virtual std::unique_ptr< PollingPolicy > clone() const =0
Return a copy of the current policy.
virtual ~PollingPolicy()=default
Represents success or an error with info about the error.
Definition: status.h:295
Contains all the Google Cloud C++ Library APIs.
Definition: async_operation.h:23
Definition: async_operation.h:22
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Definition: version.h:45
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
Definition: version.h:43