From df8fee12c4f28c349ce23a322764117ad74c98f9 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Fri, 8 Nov 2024 10:45:47 -0800 Subject: [PATCH] added docstrings to util.py --- samples/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/samples/utils.py b/samples/utils.py index 70858f38f..6bdb884c9 100644 --- a/samples/utils.py +++ b/samples/utils.py @@ -10,6 +10,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Provides helper logic used across samples +""" from google.cloud import bigtable @@ -20,6 +23,10 @@ delete_retry = Retry(if_exception_type(exceptions.TooManyRequests, exceptions.ServiceUnavailable)) class create_table_cm: + """ + Create a new table using a context manager, to ensure that table.delete() is called to clean up + the table, even if an exception is thrown + """ def __init__(self, *args, verbose=True, **kwargs): self._args = args self._kwargs = kwargs @@ -42,6 +49,9 @@ def __exit__(self, *args): def create_table(project, instance_id, table_id, column_families={}): + """ + Creates a new table, and blocks until it reaches a ready state + """ client = bigtable.Client(project=project, admin=True) instance = client.instance(instance_id) @@ -64,7 +74,14 @@ def create_table(project, instance_id, table_id, column_families={}): exceptions.FailedPrecondition, exceptions.NotFound, ) + timeout=120, ) def wait_for_table(table): + """ + raises an exception if the table does not exist or is not ready to use + + Because this method is wrapped with an api_core.Retry decorator, it will + retry with backoff if the table is not ready + """ if not table.exists(): raise exceptions.NotFound \ No newline at end of file