2

我必须以固定的时间间隔从 App Engine 触发数据流作业模板以进行修复间隔我使用过 cron 作业,但不知道如何用 Java 语言触发模板我需要以下 Java 形式的代码。

import datetime
import logging
import os

from google.appengine.ext import ndb
import webapp2

    from googleapiclient.discovery import build
    from oauth2client.client import GoogleCredentials



    class LaunchJob(webapp2.RequestHandler):

        credentials = GoogleCredentials.get_application_default()
        service = build('dataflow', 'v1b3', credentials=credentials)

        # Set the following variables to your values.
        JOBNAME = 'kiss-fn-dataflow-job'
        PROJECT = 'testing1-18001111'
        BUCKET = 'kiss-bucket'
        TEMPLATE = 'Test1'

        GCSPATH="gs://{bucket}/templates/{template}".format(bucket=BUCKET, template=TEMPLATE),
        BODY = {
            "jobName": "{jobname}".format(jobname=JOBNAME),
            "parameters": {
                "inputFile" : "gs://{bucket}/input/my_input.txt",
                "outputFile": "gs://{bucket}/output/my_output".format(bucket=BUCKET)
             },
             "environment": {
                "tempLocation": "gs://{bucket}/temp".format(bucket=BUCKET),
                "zone": "us-central1-f"
             }
        }

        request = service.projects().templates().launch(projectId=PROJECT, gcsPath=GCSPATH, body=BODY)
        response = request.execute()


    app = webapp2.WSGIApplication([
        ('/', LaunchJob),
    ], debug=True)

上面的程序运行完美,但要部署单个应用程序,Python 中的许多依赖项已经完成,并且某些功能不可用,因为我需要在 Java 中更改我的 App Engine 程序。所以我可以在我的应用程序中使用 Apache 光束。

4

0 回答 0