gax-nodejs icon indicating copy to clipboard operation
gax-nodejs copied to clipboard

feat: support Diregapic long running operation

Open summer-ji-eng opened this issue 2 years ago • 1 comments

Before the implementation, diregapic LRO return unary with compute.v1.Operation. It require manual code to poll the operation until it finish.

async function waitGlobalOperation(operation, project) {
  const globalClient = new compute.GlobalOperationsClient({fallback: 'rest'});
  for (;;) {
    const [getResp] = await globalClient.get({
      project,
      operation: operation.name,
    });
    if (getResp.status === 'DONE') {
      break;
    } else {
      await new Promise(resolve => setTimeout(resolve, 4000));
    }
  }
}

After, the sample code to call insert LRO method

const [operation] = await client.insert({
    project,
    firewallResource: resource,
  });
  const [response, metadata, third] = await operation.promise();
  console.log(response.status === 'DONE') --------> output: true;

It support Compute 4 operation polling service: GlobalOperations RegionOperations ZonalOperations GlobalOrganizationOperations

This version is not support dynamic diregapic lro, will modify with gapic-generator-typescript recognize diregapic LRO with annotation.

summer-ji-eng avatar Sep 30 '21 21:09 summer-ji-eng

Thanks @summer-ji-eng, it looks great! Left some comments, mostly style+readability. I'll defer reviewing the DIREGAPIC-specific logic to @vam-google.

alexander-fenster avatar Oct 01 '21 05:10 alexander-fenster