Control the Cloud C++ client library behavior with respect to polling on long running operations.
Some operations in Cloud services return agoogle.longrunning.Operationobject. As their name implies, these objects represent requests that may take a long time to complete, in some cases operations may take tens of seconds or even 30 minutes to complete.
The Cloud C++ client libraries models these long running operations as agoogle::cloud::future<StatusOr<T>>, whereTrepresents the final result of the operation. In the background, the library polls the service until the operation completes (or fails) and then satisfies the future.
This class defines the interface for policies that control the behavior of this polling loop.
This function is called at the beginning of the polling loop. Policies that are based on relative time should restart their timers when this function is called.
Returns
Type
Description
std::unique_ptr< PollingPolicy >
OnFailure(Status const &)
A callback to indicate that a polling attempt failed.
This is called when a polling request fails. Note that this callback is not invoked when the polling request succeeds with "operation not done".
Parameter
Name
Description
status
Status const &
Returns
Type
Description
bool
true if the failure should be treated as transient and the polling loop should continue.
WaitPeriod()
How long should the polling loop wait before trying again.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe content provides documentation for the \u003ccode\u003ePollingPolicy\u003c/code\u003e class in the Google Cloud C++ client library, which is used to manage the behavior of polling loops for long-running operations.\u003c/p\u003e\n"],["\u003cp\u003eThe latest release candidate for the library is version 2.37.0-rc, and a comprehensive list of previous versions, down to version 2.10.1, is provided for the \u003ccode\u003ePollingPolicy\u003c/code\u003e class.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ePollingPolicy\u003c/code\u003e class is designed to handle \u003ccode\u003egoogle.longrunning.Operation\u003c/code\u003e objects, which represent requests that might take a considerable time to complete, and controls the polling loop for them.\u003c/p\u003e\n"],["\u003cp\u003eThe class includes functions such as \u003ccode\u003eclone()\u003c/code\u003e, \u003ccode\u003eOnFailure(Status const &)\u003c/code\u003e, and \u003ccode\u003eWaitPeriod()\u003c/code\u003e, which allow for customization of the polling behavior, such as restarting timers, handling failures, and setting the wait time between polls.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ePollingPolicy\u003c/code\u003e class uses a \u003ccode\u003egoogle::cloud::future\u003c/code\u003e to model the long-running operations as they become completed, along with a callback system to indicate the failure of a polling attempt.\u003c/p\u003e\n"]]],[],null,["# Class PollingPolicy (2.13.0)\n\nVersion 2.13.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1PollingPolicy)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/classgoogle_1_1cloud_1_1PollingPolicy) \nControl the Cloud C++ client library behavior with respect to polling on long running operations. \nSome operations in Cloud services return a `google.longrunning.Operation` object. As their name implies, these objects represent requests that may take a long time to complete, in some cases operations may take tens of seconds or even 30 minutes to complete.\n\nThe Cloud C++ client libraries models these long running operations as a [`google::cloud::future`](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1future)`\u003c`[`StatusOr`](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e\u003e`, where `T` represents the final result of the operation. In the background, the library polls the service until the operation completes (or fails) and then satisfies the future.\n\nThis class defines the interface for policies that control the behavior of this polling loop.\n\n###### See Also\n\n\u003chttps://aip.dev/151\u003e for more information on long running operations.\n\nFunctions\n---------\n\n### clone() const\n\nReturn a copy of the current policy. \nThis function is called at the beginning of the polling loop. Policies that are based on relative time should restart their timers when this function is called.\n\n### OnFailure(Status const \\&)\n\nA callback to indicate that a polling attempt failed. \nThis is called when a polling request fails. Note that this callback is not invoked when the polling request succeeds with \"operation not done\".\n\n### WaitPeriod()\n\nHow long should the polling loop wait before trying again."]]