@@ -45,7 +45,7 @@ def _exception_class_for_grpc_status_name(name):
4545 return exceptions .exception_class_for_grpc_status (getattr (grpc .StatusCode , name ))
4646
4747
48- def _retry_from_retry_config (retry_params , retry_codes ):
48+ def _retry_from_retry_config (retry_params , retry_codes , retry_impl = retry . Retry ):
4949 """Creates a Retry object given a gapic retry configuration.
5050
5151 Args:
@@ -70,7 +70,7 @@ def _retry_from_retry_config(retry_params, retry_codes):
7070 exception_classes = [
7171 _exception_class_for_grpc_status_name (code ) for code in retry_codes
7272 ]
73- return retry . Retry (
73+ return retry_impl (
7474 retry .if_exception_type (* exception_classes ),
7575 initial = (retry_params ["initial_retry_delay_millis" ] / _MILLIS_PER_SECOND ),
7676 maximum = (retry_params ["max_retry_delay_millis" ] / _MILLIS_PER_SECOND ),
@@ -110,7 +110,7 @@ def _timeout_from_retry_config(retry_params):
110110MethodConfig = collections .namedtuple ("MethodConfig" , ["retry" , "timeout" ])
111111
112112
113- def parse_method_configs (interface_config ):
113+ def parse_method_configs (interface_config , retry_impl = retry . Retry ):
114114 """Creates default retry and timeout objects for each method in a gapic
115115 interface config.
116116
@@ -120,6 +120,8 @@ def parse_method_configs(interface_config):
120120 an interface named ``google.example.v1.ExampleService`` you would
121121 pass in just that interface's configuration, for example
122122 ``gapic_config['interfaces']['google.example.v1.ExampleService']``.
123+ retry_impl (Callable): The constructor that creates a retry decorator
124+ that will be applied to the method based on method configs.
123125
124126 Returns:
125127 Mapping[str, MethodConfig]: A mapping of RPC method names to their
@@ -151,7 +153,7 @@ def parse_method_configs(interface_config):
151153 if retry_params_name is not None :
152154 retry_params = retry_params_map [retry_params_name ]
153155 retry_ = _retry_from_retry_config (
154- retry_params , retry_codes_map [method_params ["retry_codes_name" ]]
156+ retry_params , retry_codes_map [method_params ["retry_codes_name" ]], retry_impl
155157 )
156158 timeout_ = _timeout_from_retry_config (retry_params )
157159
0 commit comments