如何使用Python代码启动数据流作业

时间:2019-02-07 14:36:08

标签: python-3.x google-cloud-platform google-cloud-functions google-cloud-dataflow

我想在将一个文件放到云存储中后启动数据流作业,然后启动一个云功能来触发它。但是我不知道如何使用Python启动datadlow作业? ?

const kickOffDataflow = (input, output) => {
var jobName = CONFIG.DATAFLOW_JOB_NAME;
var templatePath = CONFIG.TEMPLETE_FILE_PATH;
var request = {
    projectId: "test",
    requestBody: {
        jobName: jobName,
        parameters: {
            configFile: input,
            outputFile: output,
            mode: "cluster_test"
        },
        environment: {
            zone: "europe-west1-b"
        }
    },
    gcsPath: templatePath
}
console.log("Start to create " + jobName + " dataflow job");
return google.auth.getClient({
    scopes: ['https://www.googleapis.com/auth/cloud-platform']
}).then(auth => {
    request.auth = auth;
    return dataflow.projects.templates.launch(request);
}).catch(error => {
    console.error(error);
    throw error;
});

}

1 个答案:

答案 0 :(得分:1)

看看Dataflow Cloud Composer Example。它描述了如何在新文件到达GCS存储桶中时将Cloud Composer与Cloud Functions结合使用以触发基于Python的Dataflow作业。