Skip to content

Commit

Permalink
samples: long running operations - removed delays, added correct logic (
Browse files Browse the repository at this point in the history
#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 <fenster@google.com>
  • Loading branch information
Arakel2811 and alexander-fenster authored Sep 9, 2022
1 parent 98849be commit 73550e0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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..');
};

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ 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..');
};

// 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);
Expand Down
5 changes: 2 additions & 3 deletions retail/interactive-tutorials/product/set-inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 73550e0

Please sign in to comment.