Skip to content

Commit

Permalink
doc(samples): use operation to ensure createion completed
Browse files Browse the repository at this point in the history
In addition to showing the better practice (using the operation returned
from 'Instance.create' / 'Cluster.create'), this change also hardens
the sample against eventual-consistency issues.

Closes #353.
  • Loading branch information
tseaver committed Jul 9, 2021
1 parent 259d412 commit 1ef6a3f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions samples/instanceadmin/instanceadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def run_instance_operations(project_id, instance_id, cluster_id):
if not instance.exists():
print("\nCreating an instance")
# Create instance with given options
instance.create(clusters=[cluster])
operation = instance.create(clusters=[cluster])
# Enssure the operation completes.
operation.result(timeout=10)
print("\nCreated instance: {}".format(instance_id))
# [END bigtable_create_prod_instance]

Expand Down Expand Up @@ -155,7 +157,9 @@ def add_cluster(project_id, instance_id, cluster_id):
if cluster.exists():
print("\nCluster not created, as {} already exists.".format(cluster_id))
else:
cluster.create()
operation = cluster.create()
# Enssure the operation completes.
operation.result(timeout=30)
print("\nCluster created: {}".format(cluster_id))
# [END bigtable_create_cluster]

Expand Down

0 comments on commit 1ef6a3f

Please sign in to comment.