Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add job_timeout_ms to job configuration classes #1675

Merged
merged 23 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ada7d68
fix: adds new property and tests
chalmerlowe Oct 5, 2023
496472b
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 5, 2023
0cd9653
updates docs to correct a sphinx failure
chalmerlowe Oct 5, 2023
28a1fa9
Updates formatting
chalmerlowe Oct 5, 2023
5fbb7d6
Update tests/system/test_query.py
chalmerlowe Oct 5, 2023
36a2c1f
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 5, 2023
ee9ffc5
Merge branch 'main' into fix/add-job_timeout_ms
chalmerlowe Oct 9, 2023
968db9a
Update google/cloud/bigquery/job/base.py
chalmerlowe Oct 11, 2023
a3b84b4
updates one test and uses int_or_none
chalmerlowe Oct 12, 2023
b619e5b
Update tests/system/test_query.py
chalmerlowe Oct 24, 2023
be2e945
Update tests/system/test_query.py
chalmerlowe Oct 24, 2023
91edae4
testing coverage feature
chalmerlowe Oct 24, 2023
e2a05a9
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 24, 2023
d694d71
minor edits
chalmerlowe Oct 25, 2023
037417a
tweaks to noxfile for testing purposes
chalmerlowe Oct 25, 2023
4bbb4df
add new test to base as experiment
chalmerlowe Oct 25, 2023
0d9ae32
adds a test, updates import statements
chalmerlowe Nov 13, 2023
dc585d5
add another test
chalmerlowe Nov 13, 2023
aa4d302
edit to tests
chalmerlowe Nov 13, 2023
6e72fd4
formatting fixes
chalmerlowe Nov 13, 2023
69365f5
update noxfile to correct debug code
chalmerlowe Nov 14, 2023
ec05fbf
Merge branch 'main' into fix/add-job_timeout_ms
chalmerlowe Nov 14, 2023
edaaf19
removes unneeded comments.
chalmerlowe Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions google/cloud/bigquery/job/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,33 @@ def __setattr__(self, name, value):
)
super(_JobConfig, self).__setattr__(name, value)

@property
def job_timeout_ms(self):
"""Optional parameter. Job timeout in milliseconds. If this time limit is exceeded, BigQuery might attempt to stop the job.
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfiguration.FIELDS.job_timeout_ms
e.g.

job_config = bigquery.QueryJobConfig( jobtimeout = 5000 )
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
or
job_config.jobtimeout = 5000
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved

Raises:
ValueError: If ``value`` type is invalid.
"""

# None as this is an optional parameter.
if self._properties.get("jobTimeoutMs"):
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
return self._properties["jobTimeoutMs"]
return None

@job_timeout_ms.setter
def job_timeout_ms(self, value):
if not isinstance(value, int):
raise ValueError("Pass an int for jobTimeoutMs, e.g. 5000")

""" Docs indicate a string is expected by the API """
self._properties["jobTimeoutMs"] = str(value)

@property
def labels(self):
"""Dict[str, str]: Labels for the job.
Expand Down
16 changes: 16 additions & 0 deletions tests/system/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ def test_query_w_timeout(bigquery_client, query_api_method):
assert bigquery_client.cancel_job(query_job) is not None


def test_job_timeout_ms():
# Confirm that default status is None.
job_config = bigquery.QueryJobConfig()
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
assert job_config.job_timeout_ms is None

# Confirm that integers get converted to strings.
job_config.job_timeout_ms = 5000
assert job_config.job_timeout_ms == "5000" # int is converted to string


def test_job_timeout_ms_raises_valueerror():
# Confirm that attempting to set a non-integer values will raise an Error.
chalmerlowe marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(ValueError):
job_config.job_timeout_ms = "WillRaiseError"


def test_query_statistics(bigquery_client, query_api_method):
"""
A system test to exercise some of the extended query statistics.
Expand Down