Skip to content

Commit 6597598

Browse files
authored
feat: log the operation name to allow users to check the status (#12773)
* feat: log the operation name to allow users to check the status * remove blank line * Add timeout on operation polling level, not the client request
1 parent 82b281e commit 6597598

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

managedkafka/snippets/clusters/create_cluster.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ def create_cluster(
6868
)
6969

7070
try:
71+
operation = client.create_cluster(request=request)
72+
print(f"Waiting for operation {operation.operation.name} to complete...")
7173
# The duration of this operation can vary considerably, typically taking 10-40 minutes.
7274
# We can set a timeout of 3000s (50 minutes).
73-
operation = client.create_cluster(request=request, timeout=3000)
74-
print("Waiting for operation to finish...")
75-
response = operation.result()
75+
response = operation.result(timeout=3000)
7676
print("Created cluster:", response)
77-
except GoogleAPICallError:
78-
print("The operation failed with error:", operation.operation.error)
77+
except GoogleAPICallError as e:
78+
print(f"The operation failed with error: {e.message}")
7979

8080
# [END managedkafka_create_cluster]

managedkafka/snippets/clusters/delete_cluster.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ def delete_cluster(
4747

4848
try:
4949
operation = client.delete_cluster(request=request)
50+
print(f"Waiting for operation {operation.operation.name} to complete...")
5051
operation.result()
5152
print("Deleted cluster")
52-
except GoogleAPICallError:
53-
print("The operation failed with error:", operation.operation.error)
53+
except GoogleAPICallError as e:
54+
print(f"The operation failed with error: {e.message}")
5455

5556
# [END managedkafka_delete_cluster]

managedkafka/snippets/clusters/update_cluster.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ def update_cluster(
5656

5757
try:
5858
operation = client.update_cluster(request=request)
59+
print(f"Waiting for operation {operation.operation.name} to complete...")
5960
response = operation.result()
6061
print("Updated cluster:", response)
61-
except GoogleAPICallError:
62-
print("The operation failed with error:", operation.operation.error)
62+
except GoogleAPICallError as e:
63+
print(f"The operation failed with error: {e.message}")
6364

6465
# [END managedkafka_update_cluster]

0 commit comments

Comments
 (0)