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)
Answer from marian.vladoi on Stack Overflow
» pip install google-cloud-scheduler
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)
Have you tried doing:
from google.cloud.scheduler_v1.types import HttpTarget as Target
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": Target(uri: "https://us-central1-gerald-automl-test.cloudfunctions.net/automl-trainmodel-1-test-for-cron-job"),
"schedule":"1 0 * * *",
"time_zone":"utc+8",
}
training_job= client.create_job(parent,job)
I haven't tested this code, but it's clear that you're sending the string to the http_target, and the instance of it needs to be an actual HttpTarget object, and not just a string.
How to schedule python script in google cloud without using cron jobs? - Stack Overflow
Personal Project: run Python script on a schedule, text/email me to notify me of the outcome. I know I can schedule Python scripts with Scheduler & Functions, but what are my (cheap) options for the notification part?
How to Schedule Python Script to Run Every 15 Minutes?
Cloud Scheduler vs infinite loop on Google Compute Engine
Videos
You can use Google Cloud Scheduler which is a fully managed enterprise-grade cron job scheduler. It allows you to schedule virtually any job, including batch, big data jobs, cloud infrastructure operations.
The first 3 jobs per month are free. Next are $0.10 per job/month.
Yes, you will need App Engine and the Cron service to schedule those scripts. You have some more or less straight-forward options to run those scripts on GCP:
- Deploy each one as different functions, and do something as mentioned in here: Basically deploy a simple function in App Engine that sends an HTTP request to your(s) function(s).
- Deploy each one as different handlers in App Engine, and schedule each calls.
- Deploy each one as different services and then schedule the calls, bearing in mind that, if you want to schedule a call to a different service, you must specify to which one, in your
cron.yamlfile, using thetargetkeyword and the name of the service.