Skip to content

Commit 30c71f2

Browse files
fix(retail): fix retail fulfillment places tests (GoogleCloudPlatform#10495)
* Fix add_fulfillment_places.py * Fix build dependencies * Update remove_fulfillment_places.py * Use sync client for add_fulfillment_places * Use sync client for remove_fulfillment_places * Update client import * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Fix set_inventory sample --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 42e7c2c commit 30c71f2

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

retail/interactive-tutorials/product/add_fulfillment_places.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
import asyncio
1818
import random
1919
import string
20+
import time
2021

2122
from google.api_core.exceptions import GoogleAPICallError
2223
import google.auth
23-
from google.cloud.retail import AddFulfillmentPlacesRequest, ProductServiceAsyncClient
24+
from google.cloud.retail import AddFulfillmentPlacesRequest, ProductServiceClient
2425

2526
from setup_product.setup_cleanup import create_product, delete_product, get_product
2627

@@ -57,12 +58,13 @@ def get_add_fulfillment_request(
5758
async def add_places(product_name: str):
5859
print("------add fulfillment places-----")
5960
add_fulfillment_request = get_add_fulfillment_request(product_name, "store2")
60-
operation = await ProductServiceAsyncClient().add_fulfillment_places(
61-
add_fulfillment_request
62-
)
61+
operation = ProductServiceClient().add_fulfillment_places(add_fulfillment_request)
6362
# This operation doesn't have result or errors. So GoogleAPICallError will be raised.
6463
try:
65-
await operation.result()
64+
while not operation.done():
65+
print("---please wait till operation is done---")
66+
time.sleep(30)
67+
print("---add fulfillment places operation is done---")
6668
except GoogleAPICallError:
6769
pass
6870

retail/interactive-tutorials/product/remove_fulfillment_places.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
import asyncio
1818
import random
1919
import string
20+
import time
2021

2122
from google.api_core.exceptions import GoogleAPICallError
2223
from google.cloud.retail import (
23-
ProductServiceAsyncClient,
24+
ProductServiceClient,
2425
RemoveFulfillmentPlacesRequest,
2526
)
2627

@@ -52,12 +53,15 @@ def get_remove_fulfillment_request(
5253
async def remove_places(product_name: str):
5354
print("------remove fulfillment places-----")
5455
remove_fulfillment_request = get_remove_fulfillment_request(product_name, "store0")
55-
operation = await ProductServiceAsyncClient().remove_fulfillment_places(
56+
operation = ProductServiceClient().remove_fulfillment_places(
5657
remove_fulfillment_request
5758
)
5859
# This operation doesn't have result or errors. So GoogleAPICallError will be raised.
5960
try:
60-
await operation.result()
61+
while not operation.done():
62+
print("---please wait till operation is done---")
63+
time.sleep(30)
64+
print("---remove fulfillment places operation is done---")
6165
except GoogleAPICallError:
6266
pass
6367

retail/interactive-tutorials/product/set_inventory.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
import asyncio
1818
import random
1919
import string
20+
import time
2021

2122
from google.api_core.exceptions import GoogleAPICallError
2223
import google.auth
2324
from google.cloud.retail import (
2425
FulfillmentInfo,
2526
PriceInfo,
2627
Product,
27-
ProductServiceAsyncClient,
28+
ProductServiceClient,
2829
SetInventoryRequest,
2930
)
3031
from google.protobuf.field_mask_pb2 import FieldMask
@@ -86,14 +87,17 @@ def get_set_inventory_request(product_name: str) -> SetInventoryRequest:
8687
# set inventory to product
8788
def set_inventory(product_name: str):
8889
set_inventory_request = get_set_inventory_request(product_name)
89-
return ProductServiceAsyncClient().set_inventory(set_inventory_request)
90+
return ProductServiceClient().set_inventory(set_inventory_request)
9091

9192

9293
async def set_inventory_and_remove_product(product_name: str):
93-
operation = await set_inventory(product_name)
94+
operation = set_inventory(product_name)
9495
# This operation doesn't have result or errors. So GoogleAPICallError will be raised.
9596
try:
96-
await operation.result()
97+
while not operation.done():
98+
print("---please wait till operation is done---")
99+
time.sleep(30)
100+
print("---set inventory operation is done---")
97101
except GoogleAPICallError:
98102
pass
99103

0 commit comments

Comments
 (0)