我正在实施 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();
});
});