File tree Expand file tree Collapse file tree 3 files changed +22
-12
lines changed
retail/interactive-tutorials/product Expand file tree Collapse file tree 3 files changed +22
-12
lines changed Original file line number Diff line number Diff line change 1717import asyncio
1818import random
1919import string
20+ import time
2021
2122from google .api_core .exceptions import GoogleAPICallError
2223import google .auth
23- from google .cloud .retail import AddFulfillmentPlacesRequest , ProductServiceAsyncClient
24+ from google .cloud .retail import AddFulfillmentPlacesRequest , ProductServiceClient
2425
2526from setup_product .setup_cleanup import create_product , delete_product , get_product
2627
@@ -57,12 +58,13 @@ def get_add_fulfillment_request(
5758async 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
Original file line number Diff line number Diff line change 1717import asyncio
1818import random
1919import string
20+ import time
2021
2122from google .api_core .exceptions import GoogleAPICallError
2223from google .cloud .retail import (
23- ProductServiceAsyncClient ,
24+ ProductServiceClient ,
2425 RemoveFulfillmentPlacesRequest ,
2526)
2627
@@ -52,12 +53,15 @@ def get_remove_fulfillment_request(
5253async 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
Original file line number Diff line number Diff line change 1717import asyncio
1818import random
1919import string
20+ import time
2021
2122from google .api_core .exceptions import GoogleAPICallError
2223import google .auth
2324from google .cloud .retail import (
2425 FulfillmentInfo ,
2526 PriceInfo ,
2627 Product ,
27- ProductServiceAsyncClient ,
28+ ProductServiceClient ,
2829 SetInventoryRequest ,
2930)
3031from 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
8788def 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
9293async 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
You can’t perform that action at this time.
0 commit comments