0

我正在尝试使用 nodejs 来管理我的工作流程,而不是使用控制台。createWorkflow 方法返回 200 代码,但我在控制台中或在列出它时找不到它。知道缺少什么吗?打字稿 typedef 有太多的部分,无法用于需要什么和不需要什么。在下面的代码中,列表方法正确返回了我在控制台中创建的工作流名称,这证明我猜想我正确使用了父参数。但是,当我使用新工作流的名称和一些代码调用 create 方法时,我得到了这个,返回代码 200 这应该意味着它成功但找不到它。也尝试执行它返回未找到。

返回值:

{
  "_events": {},
  "_eventsCount": 2,
  "completeListeners": 0,
  "hasActiveListeners": false,
  "latestResponse": {
    "name": "projects/xxxxx/locations/us-central1/operations/operation-1607572432499-5b6141fca342d-32b153bf-bfce0551",
    "metadata": {
      "type_url": "type.googleapis.com/google.cloud.workflows.v1beta.OperationMetadata",
      "value": {
        "type": "Buffer",
        "data": [
          10,
          12,
          8,
          208,
          183,
          198,
          254,
          5,
          16,
          236,
          212,
          251,
          180,
          2,
          26,
          76,
          112,
          114,
          111,
          106,
          101,
          99,
          116,
          115,
          47,
          98,
          117,
          116,
          116,
          101,
          114,
          102,
          108,
          121,
          45,
          105,
          116,
          45,
          55,
          102,
          55,
          55,
          98,
          47,
          108,
          111,
          99,
          97,
          116,
          105,
          111,
          110,
          115,
          47,
          117,
          115,
          45,
          99,
          101,
          110,
          116,
          114,
          97,
          108,
          49,
          47,
          119,
          111,
          114,
          107,
          102,
          108,
          111,
          119,
          115,
          47,
          116,
          101,
          115,
          116,
          95,
          119,
          111,
          114,
          107,
          102,
          108,
          111,
          119,
          95,
          118,
          49,
          34,
          6,
          99,
          114,
          101,
          97,
          116,
          101,
          42,
          6,
          118,
          49,
          98,
          101,
          116,
          97
        ]
      }
    },
    "done": false
  },
  "name": "projects/xxxxxxxxxxxx/locations/us-central1/operations/operation-1607572432499-5b6141fca342d-32b153bf-bfce0551",
  "done": false,
  "longrunningDescriptor": {
    "operationsClient": {
      "auth": {
        "checkIsGCE": true,
        "jsonContent": null,
        "cachedCredential": {
          "_events": {},
          "_eventsCount": 0,
          "transporter": {},
          "credentials": {
            "access_token": "ya29.c.KpcB6AdCAMGMr_FqY7veU-uQTAP2cenQDWOh3Msaw-CPjdodjeYKAEf7lw-m1joxmam06_4QgRJ5Atnlpcm7db37CAi0lz4LS5_KPkvaodE6oefkDChOly92BxyCfaJClrKqklcEbSt1yg-2iVwngXccgwtdko9sbM4UeUihNPYScdGY0bGT484x7Ai6e2vtAfZMC2r-DqGE-g",
            "token_type": "Bearer",
            "expiry_date": 1607573907456,
            "refresh_token": "compute-placeholder"
          },
          "certificateCache": {},
          "certificateExpiry": null,
          "certificateCacheFormat": "PEM",
          "refreshTokenPromises": {},
          "eagerRefreshThresholdMillis": 300000,
          "forceRefreshOnFailure": false,
          "serviceAccountEmail": "default",
          "scopes": [
            "https://www.googleapis.com/auth/cloud-platform"
          ]
        },
        "_cachedProjectId": "xxxxxxxxxxxx",
        "defaultScopes": [
          "https://www.googleapis.com/auth/cloud-platform"
        ],
        "_getDefaultProjectIdPromise": {}
      },
      "innerApiCalls": {},
      "descriptor": {
        "listOperations": {
          "requestPageTokenField": "pageToken",
          "responsePageTokenField": "nextPageToken",
          "resourceField": "operations"
        }
      }
    }
  },
  "result": null,
  "metadata": {
    "createTime": {
      "seconds": "1607572432",
      "nanos": 647948908
    },
    "target": "projects/xxxxxxxxxxxx/locations/us-central1/workflows/test_workflow_v1",
    "verb": "create",
    "apiVersion": "v1beta"
  },
  "backoffSettings": {
    "initialRetryDelayMillis": 100,
    "retryDelayMultiplier": 1.3,
    "maxRetryDelayMillis": 60000,
    "initialRpcTimeoutMillis": null,
    "rpcTimeoutMultiplier": null,
    "maxRpcTimeoutMillis": null,
    "totalTimeoutMillis": null
  },
  "_callOptions": {
    "timeout": 30000,
    "retry": {
      "retryCodes": [],
      "backoffSettings": {
        "initialRetryDelayMillis": 100,
        "retryDelayMultiplier": 1.3,
        "maxRetryDelayMillis": 60000,
        "initialRpcTimeoutMillis": 60000,
        "rpcTimeoutMultiplier": 1,
        "maxRpcTimeoutMillis": 60000,
        "totalTimeoutMillis": 600000
      }
    },
    "autoPaginate": true,
    "otherArgs": {
      "headers": {
        "x-goog-request-params": "parent=projects%2Fxxxxxxxxxxxx%2Flocations%2Fus-central1"
      }
    },
    "bundleOptions": null,
    "isBundling": true,
    "apiName": "google.cloud.workflows.v1beta.Workflows"
  }
}

** 代码: **

engine: ExecutionsClient;
  builder: WorkflowsClient;

  location = 'us-central1';
  projectId: string;

  constructor() {
    this.engine = new ExecutionsClient();
    this.builder = new WorkflowsClient();
    this.projectId = serviceAccount.project_id;
  }


 async list(): Promise<any> {
    console.log (`list workflows`);

    const [ resp ] = await this.builder.listWorkflows({
      parent: this.builder.locationPath(this.projectId, this.location),
    });

    console.log (`listWorkflow: ${JSON.stringify(resp)}`);
    return resp;
  }

  async create(name: string, code: string): Promise<any> {

    console.log (`creating workflow named: ${name}`);

    const [ resp ] = await this.builder.createWorkflow({
      parent: this.builder.locationPath(this.projectId, this.location),
      workflow: {
        sourceContents: code,
      },
      workflowId: name
    });

    console.log (`createWorkflow: ${JSON.stringify(resp)}`);
    return resp;
  }



 async execute(name: string): Promise<any> {
    const [resp] = await this.engine.createExecution({
      parent: this.engine.workflowPath(this.projectId, this.location, name),
    });

    return resp;
  }
4

1 回答 1

0

在咨询了 google-cloud/workflows 的来源后,我发现了问题所在。createWorkflow 是他们所说的长操作,实际上是 2 个连续的承诺

const [operation] = await client.createWorkflow(request);
const [response] = await operation.promise();
于 2020-12-10T19:42:54.143 回答