简体   繁体   中英

How to update the Google Cloud scheduler with Python api

I am trying to update google scheduler job.But,it does not work well.How do I this? Now I understand what problem is.The problem is that the option class is wrong. How should I write this place?

Target(topic_name="projects/aaa/topics/bbb",data="test".encode("utf-8"))

The error message.

TypeError: Parameter to MergeFrom() must be instance of same class: expected google.cloud.scheduler.v1.PubsubTarget got PubsubTarget.

my code

import os
from google.cloud import scheduler_v1
from google.cloud.scheduler_v1 import PubsubTarget as Target

from google.protobuf import field_mask_pb2

pub = Target(topic_name="projects/aaa/topics/bbb",data="test".encode("utf-8"))

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './test.json'
client = scheduler_v1.CloudSchedulerClient()
job = { 'name': "projects/aaa/locations/us-central1/jobs/test",
       "description": "c",
       "schedule": "59 * * * *",
       "pubsub_target":pub
        }
update_mask = field_mask_pb2.FieldMask(paths=['description','schedule','pubsub_target'])

response = client.update_job(job=job,update_mask=update_mask)
print(response)


   import os
   from google.cloud import scheduler_v1
   from google.cloud.scheduler_v1 import PubsubTarget as Target



   os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './test.json'
   client = scheduler_v1.CloudSchedulerClient()

   job = Job()
   job.name = 'projects/aaa/locations/us-central1/jobs/test'
   job.description = 'c'
   job.schedule = '59 * * * *'
   job.time_zone = 'America/Los_Angeles'
   pt = Target()
   pt.topic_name = 'projects/aaa/topics/bbb'
   pt.data = 'test'.encode('utf-8')
   job.pubsub_target = pt
   job = client.create_job(parent='projects/aaa/locations/us-central1', job=job)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM