云功能的动态输入,可启动数据流作业

时间:2018-10-03 11:29:20

标签: google-cloud-functions google-cloud-dataflow google-cloud-dataprep

我正在实现Cloud Functions来触发DataPrep Dataflow作业。我可以用固定的桌子做,而且效果很好。当我尝试在随时间变化的云函数中提供表名时,当数据流作业在初始点运行时,我会得到相同的结果。

以下是代码:

const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });

//obtain table name
var currentDate = datetime.create( new Date());
var previousDate =  new Date();
previousDate.setDate(previousDate.getDate()-1);
var previousDateTime = datetime.create(previousDate);
var currentHour = currentDate.format('H');
var tableName = 'Table_Name_' + currentDate.format('Ymd');
if (currentHour == "00"){
    tableName = 'Table_Name_' + previousDateTime.format('Ymd');
}
var finalTableName='db:dataset.'+tableName;

 dataflow.projects.templates.launch({
   projectId: project-name,
   gcsPath: gcspath,
   resource: {
     parameters: {
       inputLocations: '{"location1":"'+finalTableName+'","location2":table-2}',
       outputLocations: '{"location1":"gcspath/table.csv/file","location2":output-table,"location3":"gs://dataprep-staging-a7c655be-0fa4-4e9d-8f0f-9d126b4a381d/webmaster@gizmeon.com/jobrun/recipe___4_820401/.profiler/profilerTypeCheckHistograms.json/file","location4":"gs://dataprep-staging-a7c655be-0fa4-4e9d-8f0f-9d126b4a381d/webmaster@gizmeon.com/jobrun/recipe___4_820401/.profiler/profilerValidValueHistograms.json/file"}',
       customGcsTempLocation: 'custom-gcs-path'
     },
    environment: {
      tempLocation: temp-location,
      zone: "us-central1-f"
     },
     jobName: 'bucket-hourly-schedule-' + new Date().toISOString().replace(/T/, '-').replace(/\..+/, '').replace(/:/g, '-')
   }
 }, function(err, response) {
   if (err) {
     console.error("problem running dataflow template, error was: ", err);
   }
   console.log("Dataflow template response: ", response);
   callback();
 });

});

0 个答案:

没有答案