Skip to content

Commit 84d64cd

Browse files
feat: add job_timeout_ms to job configuration classes (#1675)
* fix: adds new property and tests * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * updates docs to correct a sphinx failure * Updates formatting * Update tests/system/test_query.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update google/cloud/bigquery/job/base.py * updates one test and uses int_or_none * Update tests/system/test_query.py testing something. * Update tests/system/test_query.py * testing coverage feature * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * minor edits * tweaks to noxfile for testing purposes * add new test to base as experiment * adds a test, updates import statements * add another test * edit to tests * formatting fixes * update noxfile to correct debug code * removes unneeded comments. --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 58b3152 commit 84d64cd

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

google/cloud/bigquery/job/base.py

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from google.cloud.bigquery import _helpers
2828
from google.cloud.bigquery.retry import DEFAULT_RETRY
29+
from google.cloud.bigquery._helpers import _int_or_none
2930

3031
if typing.TYPE_CHECKING: # pragma: NO COVER
3132
from google.api_core import retry as retries
@@ -171,6 +172,37 @@ def __setattr__(self, name, value):
171172
)
172173
super(_JobConfig, self).__setattr__(name, value)
173174

175+
@property
176+
def job_timeout_ms(self):
177+
"""Optional parameter. Job timeout in milliseconds. If this time limit is exceeded, BigQuery might attempt to stop the job.
178+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfiguration.FIELDS.job_timeout_ms
179+
e.g.
180+
181+
job_config = bigquery.QueryJobConfig( job_timeout_ms = 5000 )
182+
or
183+
job_config.job_timeout_ms = 5000
184+
185+
Raises:
186+
ValueError: If ``value`` type is invalid.
187+
"""
188+
189+
# None as this is an optional parameter.
190+
if self._properties.get("jobTimeoutMs"):
191+
return self._properties["jobTimeoutMs"]
192+
return None
193+
194+
@job_timeout_ms.setter
195+
def job_timeout_ms(self, value):
196+
try:
197+
value = _int_or_none(value)
198+
except ValueError as err:
199+
raise ValueError("Pass an int for jobTimeoutMs, e.g. 5000").with_traceback(
200+
err.__traceback__
201+
)
202+
203+
""" Docs indicate a string is expected by the API """
204+
self._properties["jobTimeoutMs"] = str(value)
205+
174206
@property
175207
def labels(self):
176208
"""Dict[str, str]: Labels for the job.

noxfile.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ def system(session):
193193
session.install("-e", f".{extras}", "-c", constraints_path)
194194

195195
# Run py.test against the system tests.
196-
session.run("py.test", "--quiet", os.path.join("tests", "system"), *session.posargs)
196+
session.run(
197+
"py.test",
198+
"--quiet",
199+
os.path.join("tests", "system"),
200+
*session.posargs,
201+
)
197202

198203

199204
@nox.session(python=DEFAULT_PYTHON_VERSION)

tests/unit/job/test_base.py

+15
Original file line numberDiff line numberDiff line change
@@ -1228,3 +1228,18 @@ def test_labels_setter(self):
12281228
job_config = self._make_one()
12291229
job_config.labels = labels
12301230
self.assertEqual(job_config._properties["labels"], labels)
1231+
1232+
def test_job_timeout_ms_raises_valueerror(self):
1233+
# Confirm that attempting to set a non-integer values will raise an Error.
1234+
with pytest.raises(ValueError):
1235+
job_config = self._make_one()
1236+
job_config.job_timeout_ms = "WillRaiseError"
1237+
1238+
def test_job_timeout_ms(self):
1239+
# Confirm that default status is None.
1240+
job_config = self._make_one()
1241+
assert job_config.job_timeout_ms is None
1242+
1243+
# Confirm that integers get converted to strings.
1244+
job_config.job_timeout_ms = 5000
1245+
assert job_config.job_timeout_ms == "5000" # int is converted to string

0 commit comments

Comments
 (0)