SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
234 stars 67 forks source link

Support specifying a Default Exponential BackOffPolicy (or maybe even a custom backoff handler?) #317

Open FISHMANPET opened 3 years ago

FISHMANPET commented 3 years ago

By default, the .net libraries will retry an operation when Google returns a 503, based on the default back off policy, but there are ways to change this when creating the service object, to retry on (nearly) every exception, or to not retry at all.

This would be a rather advanced use case, but I seem to excel in those.

When constructing a service object in New-GoogleService, HttpClientInitializer and ApplicationName are passed to BaseClientService+Initializer.

Another option that can be passed is DefaultExponentialBackOffPolicy, which defaults to UnsuccessfulResponse503, but can also be Exception (triggers on any exception except Task Cancelled or Operation Cancelled) or None (which requires implementing a custom backoff handler).

At a minimum there could be a setting in the configuration that, if present, would set the backoff policy to Exception.

I don't entirely understand how a custom back off handler is implemented (it's passed into the HttpClientInitializer somehow), or if it would even be possible to specify one within this module, other than shipping compiled DLLs that implement our own backoff handlers, or requiring the user to import their own DLLs that implement their policy.