Управление рабочими процессами с помощью nodejs

#google-workflows

#google-рабочие процессы

Вопрос:

Я пытаюсь использовать nodejs для управления своими рабочими процессами вместо использования консоли. Метод createWorkflow возвращает код 200, но я не могу найти его в консоли или при его перечислении. Есть идеи, чего не хватает? typescript typedef имеет слишком много частичных элементов, чтобы быть полезным в том, что необходимо, а что нет. В приведенном ниже коде метод list корректно возвращает имена рабочих процессов, которые я создал в консоли, что доказывает, что я правильно использую родительские параметры, я полагаю. Однако, когда я вызываю метод create с именем нового рабочего процесса и некоторым кодом, я получаю this this обратно и код возврата 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/xxxxxxxxxxxx/locations/us-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;
  }
 

Комментарии:

1. к какой конечной точке вы пытаетесь дозвониться? Это создание рабочего процесса или создание выполнения?

2. Создание рабочего процесса

3. Если вы получаете статус 200, но рабочий процесс не создается, это может быть проблемой с самими рабочими процессами. Я бы порекомендовал вам обратиться к Google в их службе отслеживания проблем , если это так.

Ответ №1:

После консультации с источником для Google-cloud / workflows я обнаружил, в чем проблема. createWorkflow — это то, что они называют длительной операцией, и на самом деле это 2 последовательных обещания

 const [operation] = await client.createWorkflow(request);
const [response] = await operation.promise();