diff --git a/bigquery/google/cloud/bigquery/client.py b/bigquery/google/cloud/bigquery/client.py index 4812a31e761f..b5ef0bc4e7f2 100644 --- a/bigquery/google/cloud/bigquery/client.py +++ b/bigquery/google/cloud/bigquery/client.py @@ -686,6 +686,7 @@ def list_jobs( :class:`~google.api_core.page_iterator.HTTPIterator`. all_users (bool, optional): If true, include jobs owned by all users in the project. + Defaults to :data:`False`. state_filter (str, optional): If set, include only jobs matching the given state. One of: * ``"done"`` diff --git a/docs/bigquery/snippets.py b/docs/bigquery/snippets.py index 05a9a3655141..0e1c88019c7c 100644 --- a/docs/bigquery/snippets.py +++ b/docs/bigquery/snippets.py @@ -2297,11 +2297,31 @@ def test_client_list_jobs(client): # [START bigquery_list_jobs] # from google.cloud import bigquery # client = bigquery.Client(project='my_project') + import datetime # List the 10 most recent jobs in reverse chronological order. # Omit the max_results parameter to list jobs from the past 6 months. + print("Last 10 jobs:") for job in client.list_jobs(max_results=10): # API request(s) print(job.job_id) + + # The following are examples of additional optional parameters: + + # Use min_creation_time and/or max_creation_time to specify a time window. + print("Jobs from the last ten minutes:") + ten_mins_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=10) + for job in client.list_jobs(min_creation_time=ten_mins_ago): + print(job.job_id) + + # Use all_users to include jobs run by all users in the project. + print("Last 10 jobs run by all users:") + for job in client.list_jobs(max_results=10, all_users=True): + print("{} run by user: {}".format(job.job_id, job.user_email)) + + # Use state_filter to filter by job state. + print("Jobs currently running:") + for job in client.list_jobs(state_filter='RUNNING'): + print(job.job_id) # [END bigquery_list_jobs]