1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ # [START cloudscheduler_create_job]
1516
16- def create_scheduler_job (project_id , location_id , service_id ):
17- """Create a job with an App Engine target via the Cloud Scheduler API"""
18- # [START cloudscheduler_create_job]
19- from google .cloud import scheduler
17+ from google .cloud import scheduler
18+ from google .cloud .scheduler_v1 import Job
19+
20+
21+ def create_scheduler_job (project_id : str , location_id : str , service_id : str ) -> Job :
22+ """Create a job with an App Engine target via the Cloud Scheduler API.
23+
24+ Args:
25+ project_id: The Google Cloud project id.
26+ location_id: The location for the job.
27+ service_id: An unique service id for the job.
28+
29+ Returns:
30+ The created job.
31+ """
2032
2133 # Create a client.
2234 client = scheduler .CloudSchedulerClient ()
2335
24- # TODO(developer): Uncomment and set the following variables
25- # project_id = 'PROJECT_ID'
26- # location_id = 'LOCATION_ID'
27- # service_id = 'my-service'
28-
2936 # Construct the fully qualified location path.
3037 parent = f"projects/{ project_id } /locations/{ location_id } "
3138
@@ -45,31 +52,6 @@ def create_scheduler_job(project_id, location_id, service_id):
4552 response = client .create_job (request = {"parent" : parent , "job" : job })
4653
4754 print (f"Created job: { response .name } " )
48- # [END cloudscheduler_create_job]
4955 return response
5056
51-
52- def delete_scheduler_job (project_id , location_id , job_id ):
53- """Delete a job via the Cloud Scheduler API"""
54- # [START cloudscheduler_delete_job]
55- from google .api_core .exceptions import GoogleAPICallError
56- from google .cloud import scheduler
57-
58- # Create a client.
59- client = scheduler .CloudSchedulerClient ()
60-
61- # TODO(developer): Uncomment and set the following variables
62- # project_id = 'PROJECT_ID'
63- # location_id = 'LOCATION_ID'
64- # job_id = 'JOB_ID'
65-
66- # Construct the fully qualified job path.
67- job = f"projects/{ project_id } /locations/{ location_id } /jobs/{ job_id } "
68-
69- # Use the client to send the job deletion request.
70- try :
71- client .delete_job (name = job )
72- print ("Job deleted." )
73- except GoogleAPICallError as e :
74- print ("Error: %s" % e )
75- # [END cloudscheduler_delete_job]
57+ # [END cloudscheduler_create_job]
0 commit comments