diff --git a/managedkafka/snippets/clusters/create_cluster.py b/managedkafka/snippets/clusters/create_cluster.py index da3abc8dcbe..6de721a4081 100644 --- a/managedkafka/snippets/clusters/create_cluster.py +++ b/managedkafka/snippets/clusters/create_cluster.py @@ -68,13 +68,13 @@ def create_cluster( ) try: + operation = client.create_cluster(request=request) + print(f"Waiting for operation {operation.operation.name} to complete...") # The duration of this operation can vary considerably, typically taking 10-40 minutes. # We can set a timeout of 3000s (50 minutes). - operation = client.create_cluster(request=request, timeout=3000) - print("Waiting for operation to finish...") - response = operation.result() + response = operation.result(timeout=3000) print("Created cluster:", response) - except GoogleAPICallError: - print("The operation failed with error:", operation.operation.error) + except GoogleAPICallError as e: + print(f"The operation failed with error: {e.message}") # [END managedkafka_create_cluster] diff --git a/managedkafka/snippets/clusters/delete_cluster.py b/managedkafka/snippets/clusters/delete_cluster.py index 52de575730d..342472ec36c 100644 --- a/managedkafka/snippets/clusters/delete_cluster.py +++ b/managedkafka/snippets/clusters/delete_cluster.py @@ -47,9 +47,10 @@ def delete_cluster( try: operation = client.delete_cluster(request=request) + print(f"Waiting for operation {operation.operation.name} to complete...") operation.result() print("Deleted cluster") - except GoogleAPICallError: - print("The operation failed with error:", operation.operation.error) + except GoogleAPICallError as e: + print(f"The operation failed with error: {e.message}") # [END managedkafka_delete_cluster] diff --git a/managedkafka/snippets/clusters/update_cluster.py b/managedkafka/snippets/clusters/update_cluster.py index 8bc946dd106..9f741f489d3 100644 --- a/managedkafka/snippets/clusters/update_cluster.py +++ b/managedkafka/snippets/clusters/update_cluster.py @@ -56,9 +56,10 @@ def update_cluster( try: operation = client.update_cluster(request=request) + print(f"Waiting for operation {operation.operation.name} to complete...") response = operation.result() print("Updated cluster:", response) - except GoogleAPICallError: - print("The operation failed with error:", operation.operation.error) + except GoogleAPICallError as e: + print(f"The operation failed with error: {e.message}") # [END managedkafka_update_cluster]