首页 > 解决方案 > 从同一模板启动多个 Dataflow 作业时,如何避免“IN_USED_ADDRESSES”错误?

问题描述

我创建了一个 Dataflow 模板,它允许我将 Cloud Storage 中的 CSV 文件中的数据导入 BigQuery。我每天在特定时间使用 Cloud Function for Firebase 从这个模板创建工作。这是函数中的代码(删除了一些不相关的部分)。

const filePath = object.name?.replace(".csv", "");

      // Exit function if file changes are in temporary or staging folder
      if (
        filePath?.includes("staging") ||
        filePath?.includes("temp") ||
        filePath?.includes("templates")
      )
        return;

      const dataflow = google.dataflow("v1b3");
      const auth = await google.auth.getClient({
        scopes: ["https://www.googleapis.com/auth/cloud-platform"],
      });

      let request = {
        auth,
        projectId: process.env.GCLOUD_PROJECT,
        location: "asia-east1",
        gcsPath: "gs://my_project_bucket/templates/csv_to_bq",
        requestBody: {
          jobName: `csv-to-bq-${filePath?.replace(/\//g, "-")}`,
          environment: {
            tempLocation: "gs://my_project_bucket/temp",
          },
          parameters: {
            input: `gs://my_project_bucket/${object.name}`,
            output: biqQueryOutput,
          },
        },
      };

      return dataflow.projects.locations.templates.launch(request);

每次在 Cloud Storage 中写入任何文件时都会触发此功能。我正在使用传感器,所以至少我必须在 15 分钟内导入 89 个不同的数据,即不同的 CSV 文件。

如果同时只有 4 个工作,则整个过程运行良好。但是,当函数尝试创建第五个作业时,API 返回了许多不同类型的错误。

错误1(不准确,因为我再也找不到错误了):

Error Response: [400] The following quotas were exceeded: IN_USE_ADDRESSES

错误2:

Dataflow quota error for jobs-per-project quota. Project *** is running 25 jobs.
Please check the quota usage via GCP Console.
If it exceeds the limit, please wait for a workflow to finish or contact Google Cloud Support to request an increase in quota.
If it does not, contact Google Cloud Support.

错误 3:

Quota exceeded for quota metric 'Job template requests' and limit 'Job template requests per minute per user' of service 'dataflow.googleapis.com' for consumer 'project_number:****'.

我知道我可以间隔开开始工作以避免错误 2 和 3。但是,我不知道如何以不会填满地址的方式开始工作。那么,我该如何避免呢?如果我不能,那么我应该使用什么方法?

标签: google-cloud-platformgoogle-cloud-dataflow

解决方案



推荐阅读