Skip to content

Commit 9c0e509

Browse files
authored
doc(samples): use operation to ensure creation completed (#356)
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.
1 parent 2ad5dd8 commit 9c0e509

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/google-cloud-bigtable/samples/instanceadmin/instanceadmin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def run_instance_operations(project_id, instance_id, cluster_id):
7272
if not instance.exists():
7373
print("\nCreating an instance")
7474
# Create instance with given options
75-
instance.create(clusters=[cluster])
75+
operation = instance.create(clusters=[cluster])
76+
# Ensure the operation completes.
77+
operation.result(timeout=30)
7678
print("\nCreated instance: {}".format(instance_id))
7779
# [END bigtable_create_prod_instance]
7880

@@ -155,7 +157,9 @@ def add_cluster(project_id, instance_id, cluster_id):
155157
if cluster.exists():
156158
print("\nCluster not created, as {} already exists.".format(cluster_id))
157159
else:
158-
cluster.create()
160+
operation = cluster.create()
161+
# Ensure the operation completes.
162+
operation.result(timeout=30)
159163
print("\nCluster created: {}".format(cluster_id))
160164
# [END bigtable_create_cluster]
161165

0 commit comments

Comments
 (0)