本文介绍了如何使用Google Cloud Scheduler Python API创建工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个cron作业,该作业每天上午10点运行以触发云功能.但是,我在使用Python API时遇到了问题.当我创建工作时,它会弹出此错误.
I would like to create a cron job that will run every day at 10am to trigger a cloud function. However, I am having a problem with the Python api. When I create a job it pops out this error.
这是我的代码:
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)
推荐答案
假定utc+8 is Australia/Perth
和job that will run every day at 10am is 0 10 * * *
,则该函数应为:
Assuming utc+8 is Australia/Perth
and job that will run every day at 10am is 0 10 * * *
then the function should be:
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)
这篇关于如何使用Google Cloud Scheduler Python API创建工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!