From 73550e004ced0b535098741cbdee57d9bf20119d Mon Sep 17 00:00:00 2001 From: Arakel2811 <38522242+Arakel2811@users.noreply.github.com> Date: Fri, 9 Sep 2022 09:13:51 +0400 Subject: [PATCH] samples: long running operations - removed delays, added correct logic (#209) * Removed delays from add-fulfillment-places.js, remove-fulfillment-places.js, set-inventory.js files. * Removed delays, added correct logic. * Code clean up. Co-authored-by: Alexander Fenster --- .../interactive-tutorials/product/add-fulfillment-places.js | 4 ++-- .../product/remove-fulfillment-places.js | 4 ++-- retail/interactive-tutorials/product/set-inventory.js | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/retail/interactive-tutorials/product/add-fulfillment-places.js b/retail/interactive-tutorials/product/add-fulfillment-places.js index dcb9972a96..97dbfc290a 100644 --- a/retail/interactive-tutorials/product/add-fulfillment-places.js +++ b/retail/interactive-tutorials/product/add-fulfillment-places.js @@ -66,7 +66,8 @@ async function main(generatedProductId) { console.log('Add fulfillment request:', request); // Run request - await retailClient.addFulfillmentPlaces(request); + const [operation] = await retailClient.addFulfillmentPlaces(request); + await operation.promise(); console.log('Waiting to complete add operation..'); }; @@ -74,7 +75,6 @@ async function main(generatedProductId) { // Add fulfillment places with current time console.log('Start add fulfillment'); await calladdFulfillmentPlaces(); - await utils.delay(180000); //Get product const response = await utils.getProduct(product); diff --git a/retail/interactive-tutorials/product/remove-fulfillment-places.js b/retail/interactive-tutorials/product/remove-fulfillment-places.js index 217a72b9ab..a6b3756f04 100644 --- a/retail/interactive-tutorials/product/remove-fulfillment-places.js +++ b/retail/interactive-tutorials/product/remove-fulfillment-places.js @@ -61,7 +61,8 @@ async function main(generatedProductId) { console.log('Remove fulfillment request:', request); // Run request - await retailClient.removeFulfillmentPlaces(request); + const [operation] = await retailClient.removeFulfillmentPlaces(request); + await operation.promise(); console.log('Waiting to complete remove operation..'); }; @@ -69,7 +70,6 @@ async function main(generatedProductId) { // Remove fulfillment places with current time console.log('Start remove fulfillment'); await callRemoveFulfillmentPlaces(); - await utils.delay(180000); //Get product const response = await utils.getProduct(product); diff --git a/retail/interactive-tutorials/product/set-inventory.js b/retail/interactive-tutorials/product/set-inventory.js index 1b849cebdc..79083cad8d 100644 --- a/retail/interactive-tutorials/product/set-inventory.js +++ b/retail/interactive-tutorials/product/set-inventory.js @@ -74,14 +74,14 @@ async function main(generatedProductId) { console.log('Set inventory request:', request); // Run request - await retailClient.setInventory(request); + const [operation] = await retailClient.setInventory(request); + await operation.promise(); console.log('Waiting to complete set inventory operation..'); }; // Set inventory with current time console.log('Start set inventory'); await callSetInventory(); - await utils.delay(200000); // Get product let changedProduct = await utils.getProduct(createdProduct.name); @@ -94,7 +94,6 @@ async function main(generatedProductId) { product.priceInfo.price = 20.0; setTime = {seconds: Math.round(Date.now() / 1000) - 86400}; await callSetInventory(); - await utils.delay(200000); // Get product changedProduct = await utils.getProduct(createdProduct.name);