以同步方式通过云功能触发多个数据流作业?

时间:2021-07-19 15:35:34

I have to trigger multiple templates one by one using Google Cloud function in Google Dataflow Process. After execution of one template, the another template must be called.

我必须使用Google Dataflow Process中的Google Cloud功能逐个触发多个模板。执行一个模板后,必须调用另一个模板。

 const google = require('googleapis');
exports.goWithTheDataFlow = function(event, callback) {
 const file = event.data;
 if (file.resourceState === 'exists' && file.name) {
   google.auth.getApplicationDefault(function (err, authClient, projectId) {
     if (err) {
       throw err;
     }
     if (authClient.createScopedRequired && authClient.createScopedRequired()) {
       authClient = authClient.createScoped([
         'https://www.googleapis.com/auth/cloud-platform',
         'https://www.googleapis.com/auth/userinfo.email'
       ]);
     }

     const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
     dataflow.projects.templates.create({
       projectId: 'testing1-180111',
       resource: {
         parameters: {
         },
         jobName: 'cloud-fn-dataflow-test',
         gcsPath: 'gs://kishan-configuration/templates/FinalConfigTable'
       }
     }, function(err, response) {
       if (err) {
         console.error("problem running dataflow template, error was: ", err);
       }
       console.log("Dataflow template response: ", response);
       callback();
     });

   });
 }
};

package.json file code is this

package.json文件代码是这样的

{
  "name": "kishan_kumar464",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "google-cloud": "^0.56.0",
    "googleapis": "^22.2.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Kishan",
  "license": "ISC",
  "description": ""
}

1 个解决方案

#1


0  

If I understand correctly, you'd like to create a job from a template and wait until finish. After that, you can create the next job from the template. Correct?

如果我理解正确,你想从模板创建一个工作,并等到完成。之后,您可以从模板创建下一个作业。正确?

I think you can probably poll the job status after the job is created (job id is in the response of dataflow.projects.templates.create.

我认为您可以在创建作业后轮询作业状态(作业ID在dataflow.projects.templates.create的响应中)。

To check the status of a job, please use projects.jobs.get API.

要检查作业的状态,请使用projects.jobs.get API。

#1


0  

If I understand correctly, you'd like to create a job from a template and wait until finish. After that, you can create the next job from the template. Correct?

如果我理解正确,你想从模板创建一个工作,并等到完成。之后,您可以从模板创建下一个作业。正确?

I think you can probably poll the job status after the job is created (job id is in the response of dataflow.projects.templates.create.

我认为您可以在创建作业后轮询作业状态(作业ID在dataflow.projects.templates.create的响应中)。

To check the status of a job, please use projects.jobs.get API.

要检查作业的状态,请使用projects.jobs.get API。