From 46f68055109bfbd28f05b0cdd3771b9b7b992c29 Mon Sep 17 00:00:00 2001 From: Dan O'Meara Date: Thu, 27 Aug 2020 12:15:44 -0700 Subject: [PATCH] feat!: migrate to microgenerator (#29) * feat!: migrate to microgenerator * chore: lint and coverage fixes * chore: uses correct method in example Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> --- scheduler/snippets/create_job.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scheduler/snippets/create_job.py b/scheduler/snippets/create_job.py index f5025ca1a349..646a89780e73 100644 --- a/scheduler/snippets/create_job.py +++ b/scheduler/snippets/create_job.py @@ -27,7 +27,7 @@ def create_scheduler_job(project_id, location_id, service_id): # service_id = 'my-service' # Construct the fully qualified location path. - parent = client.location_path(project_id, location_id) + parent = f"projects/{project_id}/locations/{location_id}" # Construct the request body. job = { @@ -36,7 +36,7 @@ def create_scheduler_job(project_id, location_id, service_id): 'service': service_id }, 'relative_uri': '/log_payload', - 'http_method': 'POST', + 'http_method': 1, 'body': 'Hello World'.encode() }, 'schedule': '* * * * *', @@ -44,7 +44,12 @@ def create_scheduler_job(project_id, location_id, service_id): } # Use the client to send the job creation request. - response = client.create_job(parent, job) + response = client.create_job( + request={ + "parent": parent, + "job": job + } + ) print('Created job: {}'.format(response.name)) # [END cloud_scheduler_create_job] @@ -66,11 +71,11 @@ def delete_scheduler_job(project_id, location_id, job_id): # job_id = 'JOB_ID' # Construct the fully qualified job path. - job = client.job_path(project_id, location_id, job_id) + job = f"projects/{project_id}/locations/{location_id}/jobs/{job_id}" # Use the client to send the job deletion request. try: - client.delete_job(job) + client.delete_job(name=job) print("Job deleted.") except GoogleAPICallError as e: print("Error: %s" % e)