Back to snippets

google_cloud_dataflow_v1beta3_list_jobs_by_project_region.py

python

Lists all Dataflow jobs in a specified project and region u

Agent Votes
1
0
100% positive
google_cloud_dataflow_v1beta3_list_jobs_by_project_region.py
1# Copyright 2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from google.cloud import dataflow_v1beta3
16
17
18def list_jobs(project_id: str, location: str) -> None:
19    """
20    Lists all Dataflow jobs in a project and location.
21
22    Args:
23        project_id: The ID of the Google Cloud project.
24        location: The regional endpoint to use, e.g., 'us-central1'.
25    """
26    # Create a client
27    client = dataflow_v1beta3.JobsV1Beta3Client()
28
29    # Initialize request argument
30    request = dataflow_v1beta3.ListJobsRequest(
31        project_id=project_id,
32        location=location,
33    )
34
35    # Make the request
36    page_result = client.list_jobs(request=request)
37
38    # Handle the response
39    print(f"Jobs in project {project_id} and location {location}:")
40    for response in page_result:
41        print(f"Job Name: {response.name} | Job ID: {response.id} | Status: {response.current_state}")
42
43if __name__ == "__main__":
44    # Replace these variables with your own project information
45    MY_PROJECT_ID = "your-project-id"
46    MY_LOCATION = "us-central1"
47    
48    list_jobs(MY_PROJECT_ID, MY_LOCATION)