如何使用 Google Cloud 调度程序 Python api 创建作业

Leo*_*ung 2 python python-3.x google-cloud-platform google-cloud-scheduler

我想创建一个 cron 作业,每天上午 10 点运行以触发云功能。但是,我在使用 Python api 时遇到了问题。当我创建作业时,它会弹出此错误。

类型错误:MergeFrom() 的参数必须是同一类的实例:预期 google.cloud.scheduler.v1.HttpTarget 得到 str。

这是我的代码:

from google.cloud import scheduler_v1

project_id = XXXX
client = scheduler_v1.CloudSchedulerClient.from_service_account_json(
    r"./xxxx.json")

parent= client.location_path(project_id,'us-central1')
job={"name":"traing_for_model",
     "description":"this is for testing training model",
     "http_target":"https://us-central1-xxxx-test.cloudfunctions.net/automl-trainmodel-1-test-for-cron-job",
     "schedule":"1 0 * * *",
     "time_zone":"utc+8",
     }
training_job= client.create_job(parent,job)
Run Code Online (Sandbox Code Playgroud)

mar*_*doi 8

假设utc+8 is Australia/Perth然后 job that will run every day at 10am is 0 10 * * *函数应该是:

from google.cloud import scheduler_v1

project_id = XXXX
client = scheduler_v1.CloudSchedulerClient.from_service_account_json(
    r"./xxxx.json")

parent= client.location_path(project_id,'us-central1')

job={"name":"projects/your-project/locations/app-engine-location/jobs/traing_for_model",
     "description":"this is for testing training model",
     "http_target": {"uri":"https://us-central1-gerald-automl-test.cloudfunctions.net/automl-trainmodel-1-test-for-cron-job"},
     "schedule":"0 10 * * *",
     "time_zone":"Australia/Perth",
     }

training_job= client.create_job(parent,job)
Run Code Online (Sandbox Code Playgroud)