Package org.apache.beam.sdk.io.googleads
Class GoogleAdsV19.SimpleRateLimitPolicy
java.lang.Object
org.apache.beam.sdk.io.googleads.GoogleAdsV19.SimpleRateLimitPolicy
- All Implemented Interfaces:
GoogleAdsIO.RateLimitPolicy<com.google.ads.googleads.v19.errors.GoogleAdsError>
- Enclosing class:
GoogleAdsV19
public static class GoogleAdsV19.SimpleRateLimitPolicy
extends Object
implements GoogleAdsIO.RateLimitPolicy<com.google.ads.googleads.v19.errors.GoogleAdsError>
This rate limit policy wraps a
RateLimiter and can be used in low volume and
development use cases as a client-side rate limiting policy. This policy does not enforce a
global (per pipeline or otherwise) rate limit to requests and should not be used in deployments
where the Google Ads API quota is shared between multiple applications.
This policy can be used to limit requests across all GoogleAdsV19.Read or GoogleAdsV19.ReadAll transforms by defining and using a GoogleAdsIO.RateLimitPolicyFactory which holds a shared static GoogleAdsV19.SimpleRateLimitPolicy. Note that the desired rate must be divided by the expected
maximum number of workers for the pipeline, otherwise the pipeline may exceed the desired rate
after an upscaling event.
public class SimpleRateLimitPolicyFactory implements GoogleAdsIO.RateLimitPolicyFactory {
private static final GoogleAdsIO.RateLimitPolicy POLICY =
new GoogleAdsV19.SimpleRateLimitPolicy(1.0 / 1000.0);
@Override
public GoogleAdsIO.RateLimitPolicy getRateLimitPolicy() {
return POLICY;
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleRateLimitPolicy(double permitsPerSecond) SimpleRateLimitPolicy(double permitsPerSecond, long warmupPeriod, TimeUnit unit) -
Method Summary
Modifier and TypeMethodDescriptionvoidonBeforeRequest(@Nullable String developerToken, String customerId, Message request) Called before a request is sent.voidonError(@Nullable String developerToken, String customerId, Message request, com.google.ads.googleads.v19.errors.GoogleAdsError error) Called after a request fails with a retryable error.voidCalled after a request succeeds.
-
Constructor Details
-
SimpleRateLimitPolicy
public SimpleRateLimitPolicy(double permitsPerSecond) -
SimpleRateLimitPolicy
-
-
Method Details
-
onBeforeRequest
public void onBeforeRequest(@Nullable String developerToken, String customerId, Message request) throws InterruptedException Description copied from interface:GoogleAdsIO.RateLimitPolicyCalled before a request is sent.- Specified by:
onBeforeRequestin interfaceGoogleAdsIO.RateLimitPolicy<com.google.ads.googleads.v19.errors.GoogleAdsError>- Parameters:
developerToken- The developer token used for the request.customerId- The customer ID specified on the request.request- Any Google Ads API request.- Throws:
InterruptedException
-
onSuccess
Description copied from interface:GoogleAdsIO.RateLimitPolicyCalled after a request succeeds.- Specified by:
onSuccessin interfaceGoogleAdsIO.RateLimitPolicy<com.google.ads.googleads.v19.errors.GoogleAdsError>- Parameters:
developerToken- The developer token used for the request.customerId- The customer ID specified on the request.request- Any Google Ads API request.
-
onError
public void onError(@Nullable String developerToken, String customerId, Message request, com.google.ads.googleads.v19.errors.GoogleAdsError error) Description copied from interface:GoogleAdsIO.RateLimitPolicyCalled after a request fails with a retryable error.- Specified by:
onErrorin interfaceGoogleAdsIO.RateLimitPolicy<com.google.ads.googleads.v19.errors.GoogleAdsError>- Parameters:
developerToken- The developer token used for the request.customerId- The customer ID specified on the request.request- Any Google Ads API request.error- A retryable error.
-