|
17 | 17 |
|
18 | 18 | from grpc import StatusCode |
19 | 19 |
|
| 20 | +from google.api_core import timeout |
20 | 21 | from google.api_core.exceptions import RetryError |
21 | 22 | from google.api_core.exceptions import NotFound |
22 | 23 | from google.api_core.retry import if_exception_type |
@@ -100,10 +101,11 @@ class Table(object): |
100 | 101 | :param app_profile_id: (Optional) The unique name of the AppProfile. |
101 | 102 | """ |
102 | 103 |
|
103 | | - def __init__(self, table_id, instance, app_profile_id=None): |
| 104 | + def __init__(self, table_id, instance, mutation_timeout=None, app_profile_id=None): |
104 | 105 | self.table_id = table_id |
105 | 106 | self._instance = instance |
106 | 107 | self._app_profile_id = app_profile_id |
| 108 | + self.mutation_timeout = mutation_timeout |
107 | 109 |
|
108 | 110 | @property |
109 | 111 | def name(self): |
@@ -503,7 +505,11 @@ def mutate_rows(self, rows, retry=DEFAULT_RETRY): |
503 | 505 | sent. These will be in the same order as the `rows`. |
504 | 506 | """ |
505 | 507 | retryable_mutate_rows = _RetryableMutateRowsWorker( |
506 | | - self._instance._client, self.name, rows, app_profile_id=self._app_profile_id |
| 508 | + self._instance._client, |
| 509 | + self.name, |
| 510 | + rows, |
| 511 | + app_profile_id=self._app_profile_id, |
| 512 | + timeout=self.mutation_timeout, |
507 | 513 | ) |
508 | 514 | return retryable_mutate_rows(retry=retry) |
509 | 515 |
|
@@ -658,12 +664,13 @@ class _RetryableMutateRowsWorker(object): |
658 | 664 | ) |
659 | 665 | # pylint: enable=unsubscriptable-object |
660 | 666 |
|
661 | | - def __init__(self, client, table_name, rows, app_profile_id=None): |
| 667 | + def __init__(self, client, table_name, rows, app_profile_id=None, timeout=None): |
662 | 668 | self.client = client |
663 | 669 | self.table_name = table_name |
664 | 670 | self.rows = rows |
665 | 671 | self.app_profile_id = app_profile_id |
666 | 672 | self.responses_statuses = [None] * len(self.rows) |
| 673 | + self.timeout = timeout |
667 | 674 |
|
668 | 675 | def __call__(self, retry=DEFAULT_RETRY): |
669 | 676 | """Attempt to mutate all rows and retry rows with transient errors. |
@@ -729,7 +736,10 @@ def _do_mutate_retryable_rows(self): |
729 | 736 | inner_api_calls = data_client._inner_api_calls |
730 | 737 | if "mutate_rows" not in inner_api_calls: |
731 | 738 | default_retry = (data_client._method_configs["MutateRows"].retry,) |
732 | | - default_timeout = data_client._method_configs["MutateRows"].timeout |
| 739 | + if self.timeout is None: |
| 740 | + default_timeout = data_client._method_configs["MutateRows"].timeout |
| 741 | + else: |
| 742 | + default_timeout = timeout.ExponentialTimeout(deadline=self.timeout) |
733 | 743 | data_client._inner_api_calls["mutate_rows"] = wrap_method( |
734 | 744 | data_client.transport.mutate_rows, |
735 | 745 | default_retry=default_retry, |
|
0 commit comments